开发者

What are Managed objects and unmanaged objects in C++/CLI?

开发者 https://www.devze.com 2023-03-02 23:26 出处:网络
What are Managed 开发者_开发百科objects and unmanaged object in C++/CLIManaged objects are a feature of the .NET framework and its implementation of a C++-like language, and have their memory managed

What are Managed 开发者_开发百科objects and unmanaged object in C++/CLI


Managed objects are a feature of the .NET framework and its implementation of a C++-like language, and have their memory managed for you by the .NET garbage collector. C++ itself has no such concept, and a better (in general) way of managing all resources (not just memory) called RAII.


The concept Managed/Unmanaged is not typically C++. It is Microsoft .Net technology speak.

In normal, plain C++ applications, the application itself is responsible for deleting all the memory it has allocated. This requires the developer to be very careful about when to delete memory. If memory is deleted too soon, the application may crash if it still has a pointer to it. If memory is deleted too late, or not deleted at all, the application has a memory leak.

Environments like Java and .Net solve this problem by using garbage collectors. The developer should not delete memory anymore, the garbage collector will do this for him.

In the 'native' .Net languages (like C#), the whole language works with the garbage collector concept. To make the transition from normal, plain C++ applications to .Net easier, Microsoft added some extensions to its C++ compiler, so that C++ developers could already benefit from the advantages of .Net.

Whenever you use normal, plain C++, Microsoft talks about unmanaged, or native C++. If you use the .Net extensions in C++, Microsoft talks about managed C++. If your application contains both, you have a mixed-mode application.


Managed objects do not exist in C++.

They exist in Microsoft's .NET extensions to C++, and a complete explanation would be a bit long, sorry.

0

精彩评论

暂无评论...
验证码 换一张
取 消