how do you mix ref counted types and non- at nogc algorithms

user1234 user1234 at 12.de
Wed Jul 8 12:19:56 UTC 2020


On Wednesday, 8 July 2020 at 11:26:20 UTC, ikod wrote:
> Hello,
>
> I have ref-counted type (keeps reference to mallocated memory) 
> which I would like to release as soon as possible (when I have 
> no refs from my code).
>
> The problem is - standard algorithms can use some GC 
> allocations to keep refs to my data until GC is collected, so 
> that I have no control over memory consumption when non- at nogc

memory consumption is not your first problem (explained later)

> algorithms applied to RC data.
>
> Right now I have to avoid something like my_data.splitOn(), but 
> is there any better solution?
>
> Thanks

you must work with also on a `.dup`ed version, to leave your 
custom RC space, and later copy back the results in your ref 
counted space. Mixing two systems of memory is no joke. This can 
lead to crashes it at some point your own RC stuff are seen by 
the GC but not owned by a GC root.


More information about the Digitalmars-d mailing list