Topic: size of c/c++ structures


Author: jeff@cee.hw.ac.uk (Jeffrey Morgan)
Date: Mon, 23 Jan 1995 12:10:47 GMT
Raw View
Dear All,

I need to build a very large binary tree (possible holding 5000-10000 nodes).
Would you recommend using C structs and malloc or C++ objects using new.

Which would take up more space (the C or C++ version) and by how much?

Thanks in advance.

Jeff Morgan




Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Mon, 23 Jan 1995 16:23:39 GMT
Raw View
In <D2uxtz.5EL@cee.hw.ac.uk> jeff@cee.hw.ac.uk (Jeffrey Morgan) writes:

>I need to build a very large binary tree (possible holding 5000-10000 nodes).
>Would you recommend using C structs and malloc or C++ objects using new.

>Which would take up more space (the C or C++ version) and by how much?

 1. They are the same size.

 2. In future, such questions only belong in comp.lang.c++.
    THE GROUPS ARE NOT THE SAME!
--
 - Paul J. Lucas   #ifndef COMMON_KNOWLEDGE
   AT&T Bell Laboratories #include <stddisclaimer.h>
   Naperville, IL  #endif




Author: jongs@uxmain.nlr.nl (Sander de Jong)
Date: 25 Jan 1995 10:51:33 GMT
Raw View
In article <pjl.790878219@graceland.att.com>, pjl@graceland.att.com (Paul J. Lucas) writes:
|> In <D2uxtz.5EL@cee.hw.ac.uk> jeff@cee.hw.ac.uk (Jeffrey Morgan) writes:
|>
|> >I need to build a very large binary tree (possible holding 5000-10000 nodes).
|> >Would you recommend using C structs and malloc or C++ objects using new.
|>
|> >Which would take up more space (the C or C++ version) and by how much?
|>
|>  1. They are the same size.
|>
This is not true for HP-UX C++.
We have experienced, in the case of some complicated C struct, which needed
to be used in C++ as well, that the C++ struct is larger than the C struct.
This yields structs that contain other structs.
The C++ compiler aligns structs differently: the C compiler "looks inside"
the sub-struct to see what kind of element is first in the struct.
The C++ compiler just assumes that the sub-struct needs the same
alignment as 32 bit elements.
This has caused us some problems. (Solution: embed in the C struct some
dummy characters)
_________________________________________________________________
Sander de Jong  |  National Aerospace Laboratory, The Netherlands
jongs@nlr.nl    |  Informatics division




Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Wed, 25 Jan 1995 14:06:58 GMT
Raw View
In <3g5afm$i6v@liberator.et.tudelft.nl> jongs@uxmain.nlr.nl (Sander de Jong) writes:

>In article <pjl.790878219@graceland.att.com>, pjl@graceland.att.com (Paul J. Lucas) writes:
>|> In <D2uxtz.5EL@cee.hw.ac.uk> jeff@cee.hw.ac.uk (Jeffrey Morgan) writes:
>|>
>|> >I need to build a very large binary tree (possible holding 5000-10000 nodes).
>|> >Would you recommend using C structs and malloc or C++ objects using new.
>|>
>|> >Which would take up more space (the C or C++ version) and by how much?
>|>
>|>  1. They are the same size.
>|>
>This is not true for HP-UX C++.

 Ok: The should be the same size, otherwise your compiler is
 broken.
--
 - Paul J. Lucas   #ifndef COMMON_KNOWLEDGE
   AT&T Bell Laboratories #include <stddisclaimer.h>
   Naperville, IL  #endif