A question about moving GC

Max Samuha maxter at i.com.ua_spamless
Sun Jun 4 01:36:43 PDT 2006


On Sat, 03 Jun 2006 17:06:03 -0700, "Unknown W. Brackets"
<unknown at simplemachines.org> wrote:

>Well, you are correct that you need to do this for threaded code 
>interfacing with C functions via pointers.
>
>That doesn't mean D can't interface with C code properly, just that it 
>might not properly do it, necessarily, under this circumstance.
>
>The truth of the matter is, D is still in development, and so is the 
>standard library.  This is something that has not yet been provided for, 
>you are right.  But, as yet, no D implementation uses a compacting GC.
>
>I would suggest that a compiler that adds a compacting GC in could, 
>theoretically, detect the passing of a pointer to a C function, and 
>automatically "pin" it before the call.  Unpinning it afterward does not 
>seem practical.
>
>Another option would be to declare the variable which holds the pointer 
>as extern (C).  This could be a clear indication to the compiler that 
>this pointer should not be moved.
>
>However, the above solutions may indeed be impractical.  More thought 
>will be needed, and this thought will no doubt come from Walter.  This 
>is why, as I said, D is still in an alpha stage.
>
>Even so, I would personally just make a note near the affected area, e.g.:
>
>// !!! Passing a pointer to C.
>
>Or however you prefer to make such notes in your convention; possibly 
>noting this specifically as something to check on whenever a new 
>compiler is used.
>
>It may very well be that gc.pin() and gc.unpin() functions will be added 
>to Phobos, in which case you will need to go through these areas and 
>make the changes - just as I had to do with my code when 
>on_scope_success was changed to scope (success), and when === was 
>changed to is.
>
>It may seem like a pain, but the changes are typically minor, and the 
>benefits I see from programming in D vs. C/C++ still far outweigh these 
>problems.  I cannot predict if it's the same for you, of course.
>
>I'm American, so I may have to ask you to forgive me my poor English as 
>well.  Yours is as good as mine, whether that's a compliment or an insult.
>
>-[Unknown]

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.



More information about the Digitalmars-d-learn mailing list