digitalmars.D - Proposal: .isizeof property for compile-time instance size
- Sean Kelly (16/16) Apr 09 2006 (this was originally posted to D bugs, but turned out to be a mistake so...
- S. Chancellor (6/26) Apr 10 2006 I'd rather see my proposal implemented, and then classes be in terms of
- Sean Kelly (4/32) Apr 10 2006 As long as there's some way to get the size of classes at compile time
- Bruno Medeiros (5/11) Apr 14 2006 Why do you want this anyway?
- Sean Kelly (7/13) Apr 14 2006 Mostly to be able to construct classes in places other than GC managed
- Frank Benoit (3/7) Apr 10 2006 If you have a template for type T and want to know the size for storing
- S. Chancellor (3/11) Apr 11 2006 Having an "ideal" reference would solve a lot more problems than just
(this was originally posted to D bugs, but turned out to be a mistake so I'm reposting it here for discussion) As D lacks a lexical specifier for class reference types there is currently no way to determine the size of a class instance at compile-time. A simple solution would be to add a new property, valid for pointer and reference types, that evaluates to the size of the referenced type. Thus: (byte*).isizeof == byte.sizeof == 1 (byte**).isizeof == (byte*).sizeof == 4 (on 32-bit systems) byte.isizeof == Error: property isizeof is only valid for reference types. MyClass { int x, y; } MyClass.isizeof == 8 (MyClass*).isizeof == MyClass.sizeof == 4 (on 32-bit systems) Multiple levels of indirection can be eliminated using recursive templates, so there is no reason to collapse multiple levels of indirection and return the size of the final referenced type.
Apr 09 2006
On 2006-04-09 13:28:41 -0700, Sean Kelly <sean f4.ca> said:(this was originally posted to D bugs, but turned out to be a mistake so I'm reposting it here for discussion) As D lacks a lexical specifier for class reference types there is currently no way to determine the size of a class instance at compile-time. A simple solution would be to add a new property, valid for pointer and reference types, that evaluates to the size of the referenced type. Thus: (byte*).isizeof == byte.sizeof == 1 (byte**).isizeof == (byte*).sizeof == 4 (on 32-bit systems) byte.isizeof == Error: property isizeof is only valid for reference types. MyClass { int x, y; } MyClass.isizeof == 8 (MyClass*).isizeof == MyClass.sizeof == 4 (on 32-bit systems) Multiple levels of indirection can be eliminated using recursive templates, so there is no reason to collapse multiple levels of indirection and return the size of the final referenced type.I'd rather see my proposal implemented, and then classes be in terms of true references and then ad a "psizeof" to get the size of the physical pointer or stack variable. Of course, I would be bias toward my proposal. :) -S.
Apr 10 2006
S. Chancellor wrote:On 2006-04-09 13:28:41 -0700, Sean Kelly <sean f4.ca> said:As long as there's some way to get the size of classes at compile time I'll be happy :-) Sean(this was originally posted to D bugs, but turned out to be a mistake so I'm reposting it here for discussion) As D lacks a lexical specifier for class reference types there is currently no way to determine the size of a class instance at compile-time. A simple solution would be to add a new property, valid for pointer and reference types, that evaluates to the size of the referenced type. Thus: (byte*).isizeof == byte.sizeof == 1 (byte**).isizeof == (byte*).sizeof == 4 (on 32-bit systems) byte.isizeof == Error: property isizeof is only valid for reference types. MyClass { int x, y; } MyClass.isizeof == 8 (MyClass*).isizeof == MyClass.sizeof == 4 (on 32-bit systems) Multiple levels of indirection can be eliminated using recursive templates, so there is no reason to collapse multiple levels of indirection and return the size of the final referenced type.I'd rather see my proposal implemented, and then classes be in terms of true references and then ad a "psizeof" to get the size of the physical pointer or stack variable. Of course, I would be bias toward my proposal. :)
Apr 10 2006
Sean Kelly wrote:As long as there's some way to get the size of classes at compile time I'll be happy :-) SeanWhy do you want this anyway? -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Apr 14 2006
Bruno Medeiros wrote:Sean Kelly wrote:Mostly to be able to construct classes in places other than GC managed memory. Memory mapped files for example, fixed-size arrays within GCed classes, stack-based arrays, etc. Some of these can be accomplied using .classinfo.init.sizeof or whatever, but others require the size to be known at compile-time. SeanAs long as there's some way to get the size of classes at compile time I'll be happy :-)Why do you want this anyway?
Apr 14 2006
I'd rather see my proposal implemented, and then classes be in terms of true references and then ad a "psizeof" to get the size of the physical pointer or stack variable. Of course, I would be bias toward my proposal. :)If you have a template for type T and want to know the size for storing it T.sizeof should return 4 for a reference type. So it seems to me, a new name like ".isizeof" is better.
Apr 10 2006
On 2006-04-10 11:39:48 -0700, Frank Benoit <benoit__ __tionex.de> said:Having an "ideal" reference would solve a lot more problems than just this though.I'd rather see my proposal implemented, and then classes be in terms of true references and then ad a "psizeof" to get the size of the physical pointer or stack variable. Of course, I would be bias toward my proposal. :)If you have a template for type T and want to know the size for storing it T.sizeof should return 4 for a reference type. So it seems to me, a new name like ".isizeof" is better.
Apr 11 2006