.NET 内存管理在托管代码中比在本机代码中更快吗?
我本以为托管代码中的内存分配是否比本机代码中的内存分配更快是很清楚的 - 但似乎存在一些争议。 也许虚拟机下的内存管理速度更快,因为没有对操作系统的上下文交换调用,但后来我发现虚拟机本身需要定期调用操作系统来获取更多内存,并且它具有内存本身的管理开销而不是操作系统。
请提供支持您立场的参考文献链接,而不是像我一样做出未经证实的断言。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读 http://msdn.microsoft.com/en-us/ library/ms973852.aspx
它详细介绍了 .NET 中内存分配的工作原理,并简要地将其与 C++ 模型进行了比较。
总之,.NET 中的内存分配涉及获取当前堆栈点作为对象的地址,并将对象的数据大小添加到堆栈指针。 相比之下,C++ 必须在已释放指针列表中搜索足以容纳该对象的堆区域。 因此,在大多数情况下,.NET 会更快。
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.
听听 Wintellect 的 Jeff Richter 的说法,他是该主题的权威:
http://www. dotnetrocks.com/default.aspx?showNum=361
Listen to Jeff Richter of Wintellect, he's an authority on the subject:
http://www.dotnetrocks.com/default.aspx?showNum=361