How to make sure GC allocated resources stay around when used in C functions?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 12 12:51:43 PDT 2014


On Monday, 12 May 2014 at 19:13:28 UTC, Kagamin wrote:
> AFAIK, addRoot is for memory allocated in GC heap, and addRange 
> is for other types of memory, so you can't add non-gc memory as 
> root (just a guess, see docs). I would allocate whole Args in 
> GC heap and add is as root, yes, it would prevent collection 
> until the root is removed. A better way would be to store Args 
> in a linked list in the widget, this way it will be fully 
> managed, and Args will live as long as the widget class 
> instance references them without additional tinkering with GC.

Ah yeah, i never thought, i could allocate Args on the GC heap.

I have to allocate it on the fly and not store it in the widget 
because there could be many. I'll have a fiddle.


More information about the Digitalmars-d-learn mailing list