RFC: Pinning interface for the GC
dsimcha
dsimcha at yahoo.com
Sat Oct 13 17:07:48 PDT 2012
We already have a NO_MOVE attribute that can be set or unset.
What's wrong with that?
http://dlang.org/phobos/core_memory.html#NO_MOVE
On Saturday, 13 October 2012 at 18:58:27 UTC, Alex Rønne
Petersen wrote:
> Hi,
>
> With precise garbage collection coming up, and most likely
> compacting garbage collection in the future, I think it's time
> we start thinking about an API to pin garbage collector-managed
> objects.
>
> A typical approach that people use to 'pin' objects today is to
> allocate a chunk of memory from the C heap, add it as a root
> [range], and store a reference in it. That, or just global
> variables.
>
> 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".
>
> I propose the following functions in core.memory.GC:
>
> static bool pin(const(void)* p) nothrow;
> static bool unpin(const(void)* p) nothrow;
>
> The pin function shall pin the object pointed to by p in place
> such that it is not allowed to be moved nor collected until
> unpinned. The function shall return true if the object was
> successfully pinned or false if the object was already pinned
> or didn't belong to the garbage collector in the first place.
>
> The unpin function shall unpin the object pointed to by p such
> that it is once again eligible for moving and collection as
> usual. The function shall return true if the object was
> successfully unpinned or false if the object was not pinned or
> didn't belong to the garbage collector in the first place.
>
> Destroy!
More information about the Digitalmars-d
mailing list