digitalmars.D - class.sizeof
- Denis Koroskin (6/6) Nov 14 2008 I can't find a way to get a class sizeof property - it returns 4 (32bit ...
- Tomas Lindquist Olsen (8/16) Nov 14 2008 No nice way to do it..
- Denis Koroskin (19/34) Nov 14 2008 __traits trick works nice, thank you!
- Sean Kelly (4/26) Nov 14 2008 I added an "isizeof" proposal to the issue tracker maybe two years ago.
- Jarrett Billingsley (3/30) Nov 14 2008 But W will say "it's already accessible through __traits." Not to
- Tim M (4/39) Nov 14 2008 A few years too late to by why isn't all classes objects, an instance of...
- bearophile (5/7) Nov 14 2008 Generally I think that having a fully frozen language (D1), that can't a...
- Sean Kelly (3/10) Nov 14 2008 I don't :-) If it were, it would have been added already.
I can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.
Nov 14 2008
Denis Koroskin wrote:I can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.No nice way to do it.. auto sz = myclass.classinfo.init.length; problem this is not a compiletime constant, In D2 you can use __traits to get it... Kinda lame if you ask me :P how about .instancesizeof ? I doubt that's even a remotely common variable name ... -Tomas
Nov 14 2008
On Fri, 14 Nov 2008 21:06:39 +0300, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:Denis Koroskin wrote:__traits trick works nice, thank you! BTW, I found small inconsistency/bug: template SizeOfPointee(T) { static if (is (T t)) { enum SizeOfPointee = typeof(*t).sizeof; } } template SizeOfPointer(T) { static if (is (T t)) { enum SizeOfPointer = typeof(t).sizeof; } } int i = SizeOfPointee!(int*); // works ok int j = SizeOfPointer!(int*); // fails I believe both should work.I can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.No nice way to do it.. auto sz = myclass.classinfo.init.length; problem this is not a compiletime constant, In D2 you can use __traits to get it... Kinda lame if you ask me :P how about .instancesizeof ? I doubt that's even a remotely common variable name ... -Tomas
Nov 14 2008
Tomas Lindquist Olsen wrote:Denis Koroskin wrote:I added an "isizeof" proposal to the issue tracker maybe two years ago. Feel free to vote it up if you'd like. SeanI can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.No nice way to do it.. auto sz = myclass.classinfo.init.length; problem this is not a compiletime constant, In D2 you can use __traits to get it... Kinda lame if you ask me :P how about .instancesizeof ? I doubt that's even a remotely common variable name ...
Nov 14 2008
On Fri, Nov 14, 2008 at 2:35 PM, Sean Kelly <sean invisibleduck.org> wrote:Tomas Lindquist Olsen wrote:But W will say "it's already accessible through __traits." Not to sound fatalistic, but do you honestly think this would be added to D1?Denis Koroskin wrote:I added an "isizeof" proposal to the issue tracker maybe two years ago. Feel free to vote it up if you'd like.I can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.No nice way to do it.. auto sz = myclass.classinfo.init.length; problem this is not a compiletime constant, In D2 you can use __traits to get it... Kinda lame if you ask me :P how about .instancesizeof ? I doubt that's even a remotely common variable name ...
Nov 14 2008
A few years too late to by why isn't all classes objects, an instance of a special virtual class called Class. On Sat, 15 Nov 2008 08:55:29 +1300, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Fri, Nov 14, 2008 at 2:35 PM, Sean Kelly <sean invisibleduck.org> wrote:Tomas Lindquist Olsen wrote:But W will say "it's already accessible through __traits." Not to sound fatalistic, but do you honestly think this would be added to D1?Denis Koroskin wrote:I added an "isizeof" proposal to the issue tracker maybe two years ago. Feel free to vote it up if you'd like.I can't find a way to get a class sizeof property - it returns 4 (32bit pointer size) always. I tried many ways but still can't figure out how to do this. Documentation says that ".sizeof applied to a class object returns the size of the class reference, not the class instantiation." Is it possible? Any idea is much appreciated.No nice way to do it.. auto sz = myclass.classinfo.init.length; problem this is not a compiletime constant, In D2 you can use __traits to get it... Kinda lame if you ask me :P how about .instancesizeof ? I doubt that's even a remotely common variable name ...
Nov 14 2008
Jarrett Billingsley:But W will say "it's already accessible through __traits." Not to sound fatalistic, but do you honestly think this would be added to D1?Generally I think that having a fully frozen language (D1), that can't accept improvements, is bad. And I think that in an open source language, if enough people what to add a feature or remove a bug, and they are able to implement/do it, then it has to be doable. Begging a single person to implement all the changes or all debugging seems silly. If enough people are willing, then such feature/debugging can be added/done to LDC, for example. Bye, bearophile
Nov 14 2008
Jarrett Billingsley wrote:On Fri, Nov 14, 2008 at 2:35 PM, Sean Kelly <sean invisibleduck.org> wrote:I don't :-) If it were, it would have been added already. SeanI added an "isizeof" proposal to the issue tracker maybe two years ago. Feel free to vote it up if you'd like.But W will say "it's already accessible through __traits." Not to sound fatalistic, but do you honestly think this would be added to D1?
Nov 14 2008