How the GC distinguishes code from data

Simen kjaeraas simen.kjaras at gmail.com
Wed Jan 5 13:56:47 PST 2011


%u <wfunction at hotmail.com> 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.?)

This is hardly the code/data dualism (data can easily hold pointers), but
simply POD/pointers.


> If I have a large uint[], it's practically guaranteed to have data that  
> looks like pointers, and that might cause memory leaks.

If you have allocated a large uint[], most likely ìt will be flagged
NO_SCAN, meaning it has no pointers in it, and the GC will ignore it.


> Furthermore, if the GC moves
> things around, it would corrupt my data. How is this handled?

The current GC does not move things. One could write such a GC for D (I
believe), and in such a case data would be marked NO_MOVE if for whatever
reason it cannot be moved.


-- 
Simen


More information about the Digitalmars-d-learn mailing list