%u wrote:
> Hi,
> 
> There's a question that's been lurking in the back of my mind ever since I
> learned about D:
> 
> How does the GC distinguish code from data when determining the objects to
> collect? (E.g. void[] from uint[], size_t from void*, etc.?)
> 
> If I have a large uint[], it's practically guaranteed to have data that looks
> like pointers, and that might cause memory leaks. Furthermore, if the GC moves
> things around, it would corrupt my data. How is this handled?
> 
> Thank you!

        The GC knows about global variables, the stack, everything that was
allocated through it and everything that you tell it to scan (which
allows using C malloc without seeing an object disappear because the
only remaining pointers are in a malloc'ed buffer). Moreover, for
GC-allocated data (and maybe the globals too), the GC knows that
some data cannot contain pointers and will refrain from scanning it
(it will always assume that anything on the stack or that you tell
it to scan contains pointers).

        The GC keeps track internally of the memory where it knows there
are no pointers and the memory where there may be pointers.

                Jerome
-- 
mailto:[email protected]
http://jeberger.free.fr
Jabber: [email protected]

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to