|
|
|
|
|
by palish
6343 days ago
|
|
... allocation/deallocation is really expensive ... The cost of allocating memory in .NET (and probably other GC environments) is basically equivalent to the cost of incrementing a pointer, which is to say, basically free. The reason is because the .NET garbage collector periodically "packs together" objects in memory, so the memory allocation algorithm essentially becomes: result = _freeMemoryPtr;
_freeMemoryPtr += numBytesToAllocate;
return result;
... in other words, since objects in memory are periodically "packed together" by the GC, there isn't a lot of memory fragmentation, so the allocator can simply allocate from the end of the heap. It doesn't need to try to find a "large enough free block" within fragmented memory, because memory isn't fragmented.At least, that is my understanding. I could be wrong because I haven't investigated this thoroughly yet. http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc... |
|