This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug gcc 2.95.



>Tom,
>
>Your observations are correct, but ... Where is the bug? Is any
>program that ought to work not working because of that? Or is the
>compiler accepting a program that should not be accepted?
>
>The standard requires every object to have a different address. To
>implement that requirement, the compiler adds a single byte member to
>every empty class. In inheritance, this member also gets
>inherited. This may sound strange, but should not cause any valid C++
>program to break.
>
>Of course, there is room for optimization, to reduce memory
>consumption. With -fnew-abi, the compiler behaves as you expect. This
>is, of course, binary-incompatible to what the compiler did for the
>last few years.
>
>Hope this helps,
>Martin

I now realize older version of the GNU compiler also do the same. This is really
not a bug, in the sense that programs don't work. As you point out,
there is memory saving with using, "-fnew-abi," option. 

I am building a high performance persistant database for geometric objects.
I was following the ODMG standard, which uses inheritance to make an object
persistant. This is accomplish by overloading the new operator in an empty
base class. In our application, we have to be very concious of the memory used
by each object, for  we frequently push the limits of 32-bit machines. 
Consider the following,

class persist
{
public:
    void * operator new( size_t size );
    virtual bool foo() {}
}

class point : public class 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,

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.

The Sun Solaris compiler does compress the empty base class by default.
Which is the first smart thing I've seen it do. I been trying to get our
software ported to gcc, for we all hate the Sun Solaris development tools!
Keep up the good work on gcc.

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

Thomas W. Geocaris (tom@intimesw.com)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]