Bug gcc 2.95.

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Thu Sep 30 19:57:00 GMT 1999


> Consider the following,
> 
> class persist
> {
> public:
>     void * operator new( size_t size );
>     virtual bool foo() {}
> };
> 
> class point : public persist
> {
>     int x;
>     int y;
> 
>     bool foo() {}
> };
> 
> >From a memory usage stand point, this object requires,
> 
>     1 word for the virtual function table pointer
>     1 word for the empty base class
>     2 words for x,y members
>     1 word for a persistant-malloc implementation or such,

This computation is incorrect. Since persist has a virtual function
pointer, it is not empty, and gcc does not allocate additional data.
On a 32-bit system, sizeof(point) is 12 (i.e. three words).

> A total of 5 words for two words of persitant data. If we remove the
> virtual function table (get rid of foo()) and get rid the 1-word
> overhead for the empty base class, we reduce the memory requirement
> by amost 1/2.

I doubt that you can remove the virtual function table in any
meaningful OO application, but then, I don't know the details of your
application.

> Anyways thanks for the "-fnew-abi" tip. I'll give it a try.

Be careful, though: This is an experimental option, breaking the ABI
(as the name suggests). You would have to recompile *everything* when
using it.

Good luck,
Martin



More information about the Gcc-bugs mailing list