Size of a class instance at compile time
Daniel Keep
daniel.keep+lists at gmail.com
Sat Jan 13 10:39:53 PST 2007
Ok, ASSUMING:
1. I'm only going to be compiling with dmd...
2. ...for x86...
3. ...under Windows,
is this an accurate way of getting the size of a class instance at
compile time?
> template InstanceSize(T)
> {
> const uint InstanceSize = 12 + CountSizes!(typeof(T.tupleof));
> }
>
> template CountSizes()
> {
> const uint CountSizes = 0;
> }
>
> template CountSizes(T)
> {
> const uint CountSizes = T.sizeof;
> }
>
> template CountSizes(T, Tail...)
> {
> const uint CountSizes = T.sizeof + CountSizes!(Tail);
> }
It seems to report the right sizes, but I'm not entirely sure what the
'12' is for. Pointer to ClassInfo, ... what else?
For those wondering: I'm doing this for some custom mixin memory
allocators I'm playing with.
-- Daniel
"isizeof, isizeof, my kingdom for isizeof!"
-- "Rick 3" by Bill Wobblepike.
More information about the Digitalmars-d-learn
mailing list