|
![](/i/fill.gif) |
>> If you're using garbage collection, it's quite possible - and, indeed,
>> usual. Each time the GC collects the garbage, it also defragments the
>> free space. You therefore need only store a pointer to the next free
>> byte of memory. To allocate, just increment this pointer by the size of
>> the block allocated. Allocation is now O(1) in time and space.
>
> So far, so good. But how does the GC know how long each chunk of
> garbage-to-collect is?
The GC engine needs to know quite a bit about the objects it's scanning
- how big they are, where their pointer fields are, etc. It also usually
needs access to each thread's stack, to see what local variables are
pointing to objects. And so on and so forth. There's a /reason/ why it's
usually hard-coded into the language run-time system rather than being
an add-on library.
Post a reply to this message
|
![](/i/fill.gif) |