4 ms·
Memory allocation is one spot where C# and other languages that use generational garbage collection very well. Since the heap stays compacted there's no need t
by bunderbunder 14y ago
Memory allocation is one spot where C# and other languages that use generational garbage collection very well. Since the heap stays compacted there's no need to spend time hunting around for a sufficiently-sized chunk of free memory. You just throw the new object right on top of the heap.
The same characteristic also tends to automatically produce pretty good locality of reference without any special intervention on the part of the programmer.
On modern computers the impact of both of these can be significant. For example, in the series I linked above, the thing that motivated the optimization that let Chen finally produce something faster than the C# version was the observation that his program was spending 60% of its CPU time on the 'new' operator. And the cornerstone of the optimization was taking a cue from the way that C# handles memory allocation and implementing a sort of low-fi mimic of generational garbage collection.