On Sunday, 11 August 2013 at 16:16:26 UTC, bearophile wrote:
Maxim Fomin:
GC.sizeOf seems to return size of allocated page which is
bigger than needed (for ex. it returns 16 for a new int which
is 4).
The object instance contains a pointer to the virtual table, so
there's a way to know what object it is. With that runtime
information it should be possible to know the static size of
the instance.
Bye,
bearophile
I do not know how you can calculate precisely object size by
knowing that GC.sizeOf returns some aligned amount plus knowing
something about virtual table. In case of simple objects (like
ints) it does not work since int has no virtual table.
Anyway such guessing is useless since D provides feature to get
size of class instance (if it is defined) even in comple time
like enum S = _get_size ...