Why many programmers don't like GC?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Jan 15 15:30:08 UTC 2021


On Friday, 15 January 2021 at 15:18:31 UTC, IGotD- wrote:
> Bump the pointer is a very fast way to allocate memory but what 
> is more interesting is what happens when you return the memory. 
> What does the allocator do with chunks of free memory? Does it 
> put it in a free list, does it merge chunks? I have a feeling 
> that bump the pointer is not the complete algorithm that D uses 
> because of that was the only one, D would waste a lot of memory.

I don't know what DMD does exactly, but I guess this is called an 
"arena" or something like that? Objective-C does something 
similar with its autorelease pool.

Basically, you have a point in the call-tree where you know that 
all work has been done and then you just reclaim everything that 
is not marked as in-long-term-use. So you don't do the mark 
phase, you put the burden of marking the object as in use on the 
object/reference and just sweep. (Or assume that everything can 
be freed, which fits well with a compiler that is working in 
discrete stages).

Side note: I incidentally wrote a little allocator cache 
yesterday that at compile time takes a list of types and then 
takes the size of those types, sorts it and builds an array of 
freelists for those specific sizes and caches objects that are 
freed if they match the desired size (then there is a threshold 
for the length of the freelist, when that is hit C free() is 
called. It should be crazy fast too, since I require the free 
call to provide the type so the correct free list is found at 
compile time, not at run time.


More information about the Digitalmars-d-learn mailing list