move object from heap to stack

monarch_dodra monarchdodra at gmail.com
Wed Sep 19 10:09:24 PDT 2012


On Wednesday, 19 September 2012 at 14:16:31 UTC, Namespace wrote:
> Thanks, I will use __traits(classInstanceSize, A);
> But it does not work either.

This is because classes are already pointers. when you write 
"&a", you are getting the address of pointer itself. So when you 
memcopy, don't use "&a", but use "cast(void*)a".

What you were currently doing was memcopying the "pointer to a" 
into your chunk. From there, since you were casting to A*, 
everything worked and was legal, but you still only had 1 class 
intance. Your destroying that instance made your ap crash.

this works:
http://dpaste.dzfl.pl/8ba1f457






More information about the Digitalmars-d-learn mailing list