Why many programmers don't like GC?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 15 15:50:50 UTC 2021


On Fri, Jan 15, 2021 at 03:18:31PM +0000, IGotD- via Digitalmars-d-learn 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.

DMD *never* frees anything.  *That's* part of why it's so fast; it
completely drops the complexity of tracking free lists and all of that
jazz.

That's also why it's a gigantic memory hog that can be a big
embarrassment when run on a low-memory system. :-D

This strategy only works for DMD because a compiler is, by its very
nature, a transient process: you read in source files, process them,
spit out object files and executables, then you exit.  Add to that the
assumption that most PCs these days have gobs of memory to spare, and
this allocation scheme completely eliminates memory management overhead.
It doesn't matter that memory is never freed, because once the process
exits, the OS reclaims everything anyway.

But such an allocation strategy would not work on anything that has to
be long-running, or that recycles a lot of memory such that you wouldn't
be able to fit it all in memory if you didn't free any of it.


T

-- 
Don't throw out the baby with the bathwater. Use your hands...


More information about the Digitalmars-d-learn mailing list