Re: question about the implementation of Variant

2016-01-04 Thread aki via Digitalmars-d-learn
Thank you, Jonathan. Now I understand. On Monday, 4 January 2016 at 17:34:47 UTC, Kapps wrote: union { ubyte[size] store; // conservatively mark the region as pointers static if (size >= (void*).sizeof) void*[size / (void*).sizeof] p; } Interesting to know the way to make G

Re: question about the implementation of Variant

2016-01-04 Thread Kapps via Digitalmars-d-learn
On Monday, 4 January 2016 at 09:13:25 UTC, Jonathan M Davis wrote: On Monday, January 04, 2016 07:30:50 aki via Digitalmars-d-learn wrote: But wait, how does GC detect there still be a live reference to the object Foo? Because store is just a fix sized array of bytes. ubyte[size] store; GC canno

Re: question about the implementation of Variant

2016-01-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 04, 2016 07:30:50 aki via Digitalmars-d-learn wrote: > But wait, how does GC detect there still be a live reference to > the object Foo? > Because store is just a fix sized array of bytes. > ubyte[size] store; > GC cannot be aware of the reference, right? As I understand it, the

question about the implementation of Variant

2016-01-03 Thread aki via Digitalmars-d-learn
Following function will return the reference to a object Foo embedded in a Variant. class Foo {} Variant fun() { Variant v; v = new Foo(); return v; } According to the source code of VariantN.opAssign, the assignment is done by: memcpy(&store, &rhs, rhs.sizeof); fptr =