avatar
structure in Java??# Java - 爪哇娇娃
l*r
1
In C/C++, I like to use structure a lot to define my own (complex) data type.
However, in java, it seems the only way is to use class.
I hear class is quite slow if used as a basic complex data type (when we need
to "New" or use it a lot of times).
Any comments or ideas of this?
Thanks.
avatar
c*g
2
According to C++, structure is class, period.

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
n*k
3

The difference is not the class and struct, but the way how you can create the
data type.
Unlike C++, C#, java doesn't not support stack object, which means the only
way you can create an object is from the heap by using new operator, which is
kind of slow compared to stack memory. For example you can say
MyClass mc;
mc looks like a Stack object in C++, but if you try to use the method of mc
without initializing the mc properly, guess what, you will get a
java.lang.NullPointerException, Which m

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
e*g
4
don't worry about speed. if you are concerned write a test allocating
and dereferencing objects see how fast it is.

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
A*o
5
既然用了Java,就不要担心这些问题。
自己写个程序,测试一下速度,如果接受不了就不要用Java。

type.
need

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
m*t
6

Sigh, that's the stuff that doesn't really make you
popular on a forum, my friend.
avatar
m*t
7

If you really really (I mean *really* 8-) ) care about
performance, use a final class that has all members public.
It's as close as you can get to struct in Java.
The garbage collection in the latest JVM's has been mature
enough for us to ignore the memory-related overhead, especially
for those extra-short life objects.

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
s*M
8
just did a few simple performance test using j2sdk1.4.2_04 to compare with the
gcc compiler and MS compiler under linux and windowsXP respectively, and the
result showed the performance is almost idnetifcial. under linux compiled by
GCC, java even won by around 20%. the JVM is quite mature and efficient now. I
also like the performance of SWT under windows, quite comparable to native GUI
programs built using VC++. t

type.
need

【在 m******t 的大作中提到】
:
: If you really really (I mean *really* 8-) ) care about
: performance, use a final class that has all members public.
: It's as close as you can get to struct in Java.
: The garbage collection in the latest JVM's has been mature
: enough for us to ignore the memory-related overhead, especially
: for those extra-short life objects.

avatar
s*M
9
slow? what kind of operations are you using? in C++, structure is class by
definition, with default visibility public.

type.
need

【在 l********r 的大作中提到】
: In C/C++, I like to use structure a lot to define my own (complex) data type.
: However, in java, it seems the only way is to use class.
: I hear class is quite slow if used as a basic complex data type (when we need
: to "New" or use it a lot of times).
: Any comments or ideas of this?
: Thanks.

avatar
c*e
10
mind of showing ur code here?
I am a C/C++ programmer and just started to get some more
sense about java...
really doubt about ur conclusion of speed.

【在 s******M 的大作中提到】
: just did a few simple performance test using j2sdk1.4.2_04 to compare with the
: gcc compiler and MS compiler under linux and windowsXP respectively, and the
: result showed the performance is almost idnetifcial. under linux compiled by
: GCC, java even won by around 20%. the JVM is quite mature and efficient now. I
: also like the performance of SWT under windows, quite comparable to native GUI
: programs built using VC++. t
:
: type.
: need

avatar
r*a
11
its conclusion is obviously BS, hoho

【在 c********e 的大作中提到】
: mind of showing ur code here?
: I am a C/C++ programmer and just started to get some more
: sense about java...
: really doubt about ur conclusion of speed.

avatar
c*e
12
混混,你对MM要礼貌一点

【在 r**a 的大作中提到】
: its conclusion is obviously BS, hoho
avatar
r*a
13
i was just telling the truth, hehe, no intention of offense

【在 c********e 的大作中提到】
: 混混,你对MM要礼貌一点
avatar
r*a
14
对于各种语言在不同平台上的运行速度,前几个月有人贴过了
java几乎在所有测试参数上都比C++要慢,除了exception handling还是什么

【在 r**a 的大作中提到】
: i was just telling the truth, hehe, no intention of offense
avatar
e*g
15
who need it to be that fast.

【在 r**a 的大作中提到】
: 对于各种语言在不同平台上的运行速度,前几个月有人贴过了
: java几乎在所有测试参数上都比C++要慢,除了exception handling还是什么

avatar
st
16
just want to stop the B.S. that java is not slower and can be even faster. :D
same for c#, it's just slower and it doesnot matter, just dont say it is not

【在 e***g 的大作中提到】
: who need it to be that fast.
avatar
e*g
17
I rechecked this thread, nobody claims that. however several people
seems to have extreme difficulty of understanding plain english
and keep distoring the subject as java vs C

【在 st 的大作中提到】
: just want to stop the B.S. that java is not slower and can be even faster. :D
: same for c#, it's just slower and it doesnot matter, just dont say it is not

avatar
c*e
18
including me .haha
but u have to admit it is kinda confusing.
were talking about the speed diff between c++ and java then someone
jumped out and give out some benchmark stats..

【在 e***g 的大作中提到】
: I rechecked this thread, nobody claims that. however several people
: seems to have extreme difficulty of understanding plain english
: and keep distoring the subject as java vs C

avatar
st
19
summerMM used to claim that, said it used gcc and java vesion is faster
some time, blah blah... //sniff
"obvious thing can be wrong" is quite obvious to you, right?
wait, found it:
发信人: summerMM (艳阳天~~), 信区: Java
标 题: Re: structure in Java??
发信站: Unknown Space - 未名空间 (Wed May 5 09:19:10 2004) WWW-POST
just did a few simple performance test using j2sdk1.4.2_04 to compare with the
gcc compiler and MS compiler under linux and windowsXP respectively, and the
result showed the performance is almost

【在 e***g 的大作中提到】
: I rechecked this thread, nobody claims that. however several people
: seems to have extreme difficulty of understanding plain english
: and keep distoring the subject as java vs C

avatar
st
20
another bgbj

【在 c********e 的大作中提到】
: including me .haha
: but u have to admit it is kinda confusing.
: were talking about the speed diff between c++ and java then someone
: jumped out and give out some benchmark stats..

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。