RFC: Pinning interface for the GC

Alex Rønne Petersen alex at lycus.org
Sat Oct 13 12:34:26 PDT 2012


On 13-10-2012 21:24, David Nadlinger wrote:
> On Saturday, 13 October 2012 at 18:58:27 UTC, Alex Rønne Petersen wrote:
>> This is kind of terrible because adding the chunk of memory as a root
>> forces the GC to actually scan it, which is unnecessary when what you
>> really want is to pin the object in place and tell the GC "I know what
>> I'm doing, don't touch this".
>
> If pointers in pinned objects make their targets live, there would be no
> difference to simply adding the object as a root. So in your proposal,
> pinned objects are implicitly marked live if they aren't reachable from
> any of the roots, but any other objects reachable only from a pinned
> object but not from a root would be collected – correct?
>
> David

There is a difference: Adding the object itself as a root does not 
actually guarantee that the object *itself* might not be collected. At 
least, this is how I have to assume things work given that this is not 
guaranteed here: http://dlang.org/phobos/core_memory.html#addRoot

As for your question: Not quite. A pinned object that points to any 
other unpinned objects will implicitly keep those alive. This is at 
least how I would expect it to work, following the principle of least 
surprise.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list