🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #512

sizeof(Class) vs. size passed to Class::new

#512
From: Michael Tiemann
Date: Tue, 17 Oct 1989 22:05
33 lines
1823 bytes
   Date: Tue, 17 Oct 89 12:41:35 -0600
   From: grunwald@foobar.colorado.edu (Dirk Grunwald)
   Reply-To: grunwald@foobar.colorado.edu
   Office: 6-1 EECR (303) 492-0452


   If you define an overloaded new, you're passed the size of the
   structure you are to allocate.

   In the latest g++.xtar.Z, this differs from the value returned via
   ``sizeof'' for that class. Is this intentional?

   For example, in one class I have, operator new is passed a size of 183
   while sizeof returns 176.

   Does the sizeof() operator omit space for vtable pointers? Why 7 bytes
   different?

   Is this a bug or a feature?

   Dirk Grunwald -- Univ. of Colorado at Boulder	(grunwald@foobar.colorado.edu)

Your class has an object which requires 8 byte alignment.  Since
malloc does not, a priori, give you reasonably aligned memory, I make
the compiler ask for enough that it can cause that memory to be
appropriately aligned.  The way I implement this assumes a minimum
alignment from malloc.  Conservatively this would be 1 byte, but it
would be inefficient to force alignment of every call to malloc, so I
assume malloc returns chunks which are aligned enough for a pointer.
In most cases, this is four bytes.

Michael
Technical Details
Message-ID: <8910172205.AA10710@lurch.Stanford.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!uakari.primate.wisc.edu!ginosko!cs.utexas.edu!mailrus!tut.cis.ohio-state.edu!LURCH.STANFORD.EDU!tiemann
References: <8910171841.AA07303@foobar.colorado.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!uakari.primate.wisc.edu!ginosko!cs.utexas.edu!mailrus!tut.cis.ohio-state.edu!LURCH.STANFORD.EDU!tiemann
From: tiemann@LURCH.STANFORD.EDU (Michael Tiemann)
Newsgroups: gnu.g++.bug
Subject: sizeof(Class) vs. size passed to Class::new
Message-ID: <8910172205.AA10710@lurch.Stanford.EDU>
Date: 17 Oct 89 22:05:01 GMT
References: <8910171841.AA07303@foobar.colorado.edu>
Sender: daemon@tut.cis.ohio-state.edu
Reply-To: tiemann@lurch.stanford.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 33