On Tue, 27 Apr 2004 11:58:27 +0000 (UTC), Wellu Mäkinen
<wellu@n0spamN0rHTml.w3llu.0r9.invalid> wrote:
[color=blue]
>On 2004-04-27, John Harrison <john_andronicus@hotmail.com> wrote:[color=green]
>> I didn't mean your posted code was meaningless. I meant that writing code
>> whose structure reflects the task for which it is designed is far more
>> important than worrying about the efficiency of structs or ints. If four
>> integers have some logical connection in the task you are doing then the
>> should go into a struct (or class) for that reason alone. The relative
>> efficiency of structs, class and ints should not be a consideration.[/color]
>
> Symbian OS for instance has 8 kilobytes of stack. If I
> don't care of "relative efficiency" at all then my code
> becomes useless. The four integers were only an
> example. The struct or class could be far more
> complicated.. Maybe I need to allocate thousands of them as
> fast as possible. So the question was totally theoritacal
> and its purpose was to find out which one, either class or
> struct, to use when I need speed, small size etc.
>
> But as replied it doesn't really matter which one to
> use.[/color]
A really good compiler will treat:
A a;
as equivalent to
int a, b, c, d;
for code generation purposes for both the class and struct version.
e.g. if any of a, b, c or d aren't used, they will be removed
entirely. They might also be arbitrarily reordered if this produces
better code. Any compiler with a "small object optimizer" should be
able to do that. Kai C++ was famous for it, and I hope other compilers
have caught up (judging recent runs of C++ abstraction penalty tests,
I think they probably have).
Tom
--
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html