move object from heap to stack

monarch_dodra monarchdodra at gmail.com
Wed Sep 19 12:53:28 PDT 2012


On Wednesday, 19 September 2012 at 19:24:34 UTC, Namespace wrote:
> Result:
> http://dpaste.dzfl.pl/24988d8f

I like it, but how can something placed on the stack be reference 
counted? The "chunk" is also placed on the stack, so it doesn't 
really make sense to me: When the object goes out of scope, the 
chunk goes, regardless of ref count. I think you should ditch the 
whole ref count thing.

You'll also have to be aware of the dangers of putting a class 
instance on the stack:

main()
{
     A a;
     {
         stacked_obj!A so;
         so.gen;
         a = so.get;
     }
     a.print(); //<-- undefined, with or without reference count
}

IE: Big red comment you should NEVER extract an instance from the 
stack.


More information about the Digitalmars-d-learn mailing list