News for hackers. Stuff that matters.
Re:Organizations Using the D Language by Thiez on Tuesday February 16, 2021 @05:55PM (#26159847)
How does that work? As I understand it the D GC scans the stack and the GC heap memory for pointers (or values looking like pointers) to determine which objects are reachable. But can the GC scan memory allocated by malloc? How does it know whether a value allocated with malloc has since been freed?
Re:Organizations Using the D Language by mhh__ on Tuesday February 16, 2021 @06:22PM (#26160132)
The GC is precise where it matters but has no interest in memory you allocate yourself (exceptions to this rule exist but they're fairly obvious). You don't need to worry about it nearly always.
Re:Organizations Using the D Language by Thiez on Tuesday February 16, 2021 @06:39PM (#26160331)
So you don't want to store pointers to GC objects in memory allocated yourself, or it may get freed if there are no other pointers? Seems like quite the footgun.
Re:Organizations Using the D Language by destructionator on Tuesday February 16, 2021 @07:08PM (#26160693)
You do have to be legitimately careful with that. I've tripped myself before while sending objects through a self-pipe. The D GC only runs upon a function call, so with a bit of care you can defer runs, but here I allocated a new object while another one was still in the kernel's pipe buffer... and the GC assumed it was dead since it can't see that buffer and reused its memory for the new object. Took me a while to realize what was going on.

But on the other hand, I write a lot of D code and often go back to that same story because it isn't terribly common anyway and easy to manage when you know how. Just yeah if you are mixing techniques without knowing the potential issue you can have trouble.

Re:Organizations Using the D Language by mhh__ on Tuesday February 16, 2021 @06:41PM (#26160361)
Basically in this situation you have to inform the GC but realistically this extremely rare in practice.

Of the issues the GC has, this isn't one of 'em.

Re:Organizations Using the D Language by david2ndaccount on Tuesday February 16, 2021 @06:20PM (#26160110)
You call a function to register and deregister a region of memory as potentially holding pointers to Gc-allocated memory.
Re:Organizations Using the D Language by Thiez on Tuesday February 16, 2021 @06:43PM (#26160381)
Right, but if you do that, is there any advantage over just allocating that memory directly from the GC instead of calling malloc and then registering the memory?