Not in the slightest true. The reality is good best fit allocators in c run an average of 17 instructions per call.
Yes that's true, but I think it misses another point. C and C++ both also do stack allocation which runs in zero cycles. The memory is pre-allocated and simply accessed by indexing via the stack pointer.
The code I write often makes heavy use of local fixed sized objects such as fixed dimensionality vectors. The C++ stdlib now pretty much specifies that strings use this trick for the "short string optimization", too.
C and C++ also do things like arena allocation, can embed structs into each other and tend to reuse more buffers if not for else due to the fact that you need to keep track of them anyway to free them so you might as well reuse them. This is doubly true for C where you don't have the temptation to use higher level abstractions that obscure inefficiencies.
So not only is it possible to do more efficient memory management, it actually gets used due to the languages guiding the programmer in that direction, and also due to cultural reasons.
I may be misunderstanding one or even both of you, but aren't you and /u/headius talking about different things?
I got the impression he wasn't referring to specific allocators, more the happy coincidence that freeing and allocing the same size of memory in a tight-loop would mostly end-up using the exact slice of memory? Where-as a GC memory model would always provide you with "the next slice" of memory? Although having said that I'm still not sure why cache would be a factor in that case if it's freed at the end of the loop anyway.
This would only be a benefit in tight-loops called upon thousands of times, in other circumstances the memory allocations would be less predictable and other forces would be at work.
This is unlikely to yield the expected caching benefits as allocators tend to use first in first out structures to store their free chunks of the same size sans the trie node
You only have to walk all live nodes, and (with generational gc) the long-living ones are only walked when you're close to OOM. If your new generation is properly sized, most of the shortliving stuff is already dead and has no cost. Edit: most GCs are not compacting, and since c allocaters usually aren't either, compaction cost is not really relevant here.
0
u/[deleted] Jul 06 '15
[deleted]