non-determinant object lifetime and memory management
bearophile
bearophileHUGS at lycos.com
Sat Nov 30 01:24:26 PST 2013
Frustrated:
> I need to pass around some objects(specifically int[]) that may
> be used by several other objects at the same time. While I
> could clone these and free them when the parent object is done
> this wastes memory for no real reason except ease of use.
>
> Since many objects may contain a ptr to the array, what would
> be the best way to deal with deallocating them? I could wrap
> the array in a collection an use ARC but is there a better way?
>
> Is there something in std.allocators that can help?
>
> (Should be obvious that I'm trying to avoid the GC)
Your use case seems fit for using the GC.
Otherwise take a look at std.typecons.RefCounted, to be used in a
wrapper that uses "alias this".
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list