Article View: gnu.g++.bug
Article #49G++ bug for forwarding to developers
From: Jeff Gehlhaar
Date: Wed, 04 Nov 1992 07:59
Date: Wed, 04 Nov 1992 07:59
39 lines
1877 bytes
1877 bytes
What follows came from one of my users...
>// A class that has no data members should have a size of zero so that
>// classes that are derived from it aren't needlessly expanded in size.
>// This would not normally be a problem, but my program allocates almost
>// 250,000 small derived class elements, and the base class being a non-
>// zero size bloats the required memory by a megabyte.
>
>// If the empty base class cannot be made size zero because of implementation
>// restrictions, at least the derived class should not be made bigger. An
>// increase of an eight-byte element to twelve bytes is a 50% overhead.
>
>#include <iostream.h>
>#include <stddef.h>
>
>class NeverFreed { // special memory management strategy for
>public: // data elements that are never freed
> void *operator new(size_t);
>};
>
>class Derived : public NeverFreed
>{ // on a 32-bit machine, this should be eight bytes
> Derived *next;
> long item;
>};
>
>int
>main(void)
>{
> if (sizeof(class Derived) == 8)
> return 0;
> cout << "The size of an empty class is "
> << sizeof(class NeverFreed)
> << " and the derived class "
> << sizeof(class Derived)
> << endl;
> return 1;
>}
Technical Details
Message-ID:
<9211042259.AA16859@harvey>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qualcomm.com!jbgShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qualcomm.com!jbg From: jbg@qualcomm.com (Jeff Gehlhaar) Subject: G++ bug for forwarding to developers Message-ID: <9211042259.AA16859@harvey> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Wed, 4 Nov 1992 07:59:38 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 43