Obtaining aligned addresses and aligned spaces for objects

Steven Schveighoffer schveiguy at yahoo.com
Wed Jun 29 07:47:39 PDT 2011


On Wed, 29 Jun 2011 01:42:37 -0400, Ali Çehreli <acehreli at yahoo.com> wrote:
> On a related note, why doesn't __traits(classInstanceSize, T) consider
> the padding bytes? If I'm not mistaken struct sizes do include the
> padding bytes. The following class has the very odd size of 17! Is that
> by design?

Probably it's because classes are intended to occupy their own memory  
block, so the pad doesn't matter, you can't put two in the same block  
anyways.

If you want to do it, I think it should be possible.  But I don't think it  
would work great if you put two classes in the same block without  
significant compiler/GC changes.

That being said, given that all GC blocks are at least 16-byte aligned,  
the same should hold true for any class instance.

-Steve


More information about the Digitalmars-d-learn mailing list