托管和非托管
如果.net dll同时包含托管和非托管代码,代码将如何转换为CIL以及CLR如何分配和管理内存
if a .net dll contains both managed and unmanaged code , how does the code will be converted to CIL and how CLR allocate and manages the memory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据定义,非托管代码不由 CLR 管理。它不会转换为 CIL,CLR 也不会为其分配或管理内存。这只发生在托管代码上。
当您在 .NET 程序集中编写非托管代码时,您是在指示编译器和运行时将事情交给您自己处理。您将负责内存管理,就像编写本机代码一样。
The unmanaged code is by definition not managed by the CLR. It will not be converted to CIL, and the CLR will neither allocate nor manage memory for it. That only happens for the managed code.
When you write unmanaged code in a .NET assembly, you're instructing the compiler and the run-time that you want to take matters into your own hands. You become responsible for memory management, just as if you were writing native code.