A question about moving GC

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Fri Jun 9 10:26:31 PDT 2006


Walter Bright wrote:
> Stewart Gordon wrote:
>> Walter Bright wrote:
>>> Max Samuha wrote:
>>>> Thank you for the extensive explanation!
>>>> Marking my code with '// !!! Passing a pointer to C.' is what i've
>>>> been doing recently:) and it seems the best solution for now until
>>>> ares is mature or phobos has pin/unpin, or pointers passed to C are
>>>> pinned implicitly.
>>>
>>> They will be pinned implicitly, no need to call pin/unpin. The only 
>>> time you're going to have a problem is if the C routine hides the 
>>> pointer in a malloc'd buffer where the gc won't see it. The gc *will* 
>>> see pointers on the C stack.
>>
>> Would it remain pinned indefinitely, until the C function exits, or 
>> until the program explicitly unpins it by some means?
> 
> It's pinned because it's on the stack, just like pointers on the stack 
> for your D functions. The gc doesn't know the difference.

Whoa, I got a bit confused here. Is any reference that is held in the 
stack automatically pinned (i.e., the referred data doesn't move) ? If 
so, why is that, why wouldn't a moving collector move it?

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-learn mailing list