www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.variant, elaborate copying and GC

reply "Yuriy" <yuriy.glukhov gmail.com> writes:
Hello, i've been playing around with std.variant and noticed, 
that it does not support elaborate copying, when a struct uses 
one. So the question is whether it is intended or not. If yes, 
std.variant should probably prohibit usage of such structs. If 
no, then it we will need to add a destructor and, and handle 
destruction in std.Variant.handler, which will introduce some 
performance drop.
Also, i can't completely understand how garbage collection works. 
E.g. setting an instance of a class to std.variant will copy its 
reference to variant's internal storage, which is void[]. Will GC 
loose track of such reference? Thanx.
Apr 08 2014
next sibling parent "Yuriy" <yuriy.glukhov gmail.com> writes:
Sorry for all the typos. It's been a long day =).
Apr 08 2014
prev sibling parent reply "Rene Zwanenburg" <renezwanenburg gmail.com> writes:
On Tuesday, 8 April 2014 at 16:03:01 UTC, Yuriy wrote:
 Also, i can't completely understand how garbage collection 
 works. E.g. setting an instance of a class to std.variant will 
 copy its reference to variant's internal storage, which is 
 void[]. Will GC loose track of such reference? Thanx.
It won't. There has been some work on a precise GC but I don't know how much is being used at the moment. In any case, for untyped memory the GC will assume the worst and treat every word as a potential pointer.
Apr 08 2014
parent "Yuriy" <yuriy.glukhov gmail.com> writes:
Ah, now that's clear. Ok, what about the other question? E.g. I'm 
trying to implement a bridge to C lib with reference counting. My 
"references" are structs. Ctor retains, dtor releases, assign 
does both. Looks like my struct can not be used with variants. 
Should i submit a pull to fix that?
Apr 08 2014