I would have thought that it would be clear cut whether memory allocation is faster in managed code than in native code - but there seems to be some controversy. Perhaps memory management under a Virtual Machine be faster because of no context-swapping calls to the OS, but then I see that the VM would itself need to make periodic calls to the OS for more memory, and it has the management overheads the memory itself rather than the OS.
Rather than making unsubstantiated assertions like I have, please provide links to references that support your position.
Take a read of http://msdn.microsoft.com/en-us/library/ms973852.aspx
It goes into some details on how memory allocation works in .NET and briefly compares it to the C++ model.
In summary, memory allocation in .NET involves grabbing the current stack point as the object's address and adding the object's data size to the stack pointer. C++ by comparison has to search through a list of freed pointers for an area of the heap large enough for the object. In most cases therefore, .NET will be faster.
Listen to Jeff Richter of Wintellect, he's an authority on the subject:
http://www.dotnetrocks.com/default.aspx?showNum=361
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With