托管 c++ 和 c++ 之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/114238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between managed c++ and c++
提问by nutario
The topics title is actually my question. And the second question is: When do I use what of these two?
主题标题实际上是我的问题。第二个问题是:我什么时候使用这两个?
回答by Laurent
When not specified, C++ is unmanaged C++, compiled to machine code. In unmanaged C++ you must manage memory allocation manually.
如果未指定,C++ 是非托管 C++,编译为机器代码。在非托管 C++ 中,您必须手动管理内存分配。
Managed C++ is a language invented by Microsoft, that compiles to bytecode run by the .NET Framework. It uses mostly the same syntax as C++ (hence the name) but is compiled in the same way as C# or VB.NET; basically only the syntax changes, e.g. using '->' to point to a member of an object (instead of '.' in C#), using '::' for namespaces, etc.
托管 C++ 是 Microsoft 发明的一种语言,可编译为由 .NET Framework 运行的字节码。它主要使用与 C++ 相同的语法(因此得名),但编译方式与 C# 或 VB.NET 相同;基本上只有语法变化,例如使用“->”指向对象的成员(而不是C#中的“.”),使用“::”作为命名空间等。
Managed C++ was made to ease transition from classic C++ to the .NET Framework. It is not intended to be used to start new projects (C# is preferred).
托管 C++ 旨在简化从经典 C++ 到 .NET Framework 的过渡。它不打算用于启动新项目(首选 C#)。
回答by TraumaPony
"Managed C++" refers to a language that was included in Visual Studio.NET/VisualStudio.NET 2003. It has since been deprecated, with the latest .net C++ being C++/CLI.
“托管 C++”是指包含在 Visual Studio.NET/VisualStudio.NET 2003 中的一种语言。它已被弃用,最新的 .net C++ 是 C++/CLI。
回答by TraumaPony
You can code native C++ two different ways. The first is compiling directly to machine code with just the operating system between you and the Platform ( Hardware ). The second native coding is done with MFC ( Microsoft Foundation Classes ). This is the same as the first example except for the use of MFC.
您可以通过两种不同的方式编写本机 C++。第一种是直接编译为机器代码,仅使用您和平台(硬件)之间的操作系统。第二个本地编码是使用 MFC(Microsoft 基础类)完成的。除了使用 MFC 之外,这与第一个示例相同。
Managed C++ uses the CLR ( Common Language Runtime ) The CLR along with the .net framework class libraries make up the .NET Framework. This managed C++/CLI standard uses the .Net framework along with the MSIL ( Microsoft Intermediate Language ). This standard works by mapping to machine code only when the program is executing by the use of a just in time compiler. If your code will be running on different hardware platforms the use of managed code will be much easier. As with all thing there is a slight price to pay for convenience, as native code will run faster.
托管 C++ 使用 CLR(公共语言运行时) CLR 与 .net 框架类库一起构成了 .NET 框架。此托管 C++/CLI 标准使用 .Net 框架和 MSIL(微软中间语言)。该标准仅在程序通过使用即时编译器执行时映射到机器代码来工作。如果您的代码将在不同的硬件平台上运行,那么托管代码的使用会容易得多。与所有事情一样,为了方便需要付出一点代价,因为本机代码会运行得更快。
回答by GSerg
I think you should look at this question.
我觉得你应该看看这个问题。
回答by radu_c
You'll be using managed C++ when want to use a native C++ class library from managed code. In this case you wrap unmanaged classes in managed C++ ones, then you use them in any CLR language.
当想要从托管代码使用本机 C++ 类库时,您将使用托管 C++。在这种情况下,您将非托管类包装在托管 C++ 类中,然后在任何 CLR 语言中使用它们。
回答by hayalci
Managed C++ means that memory allocation, management, garbage collection is handled by the virtual machine. Whereas in "regular" C++ you would have to allocate and deallocate memory.
托管 C++ 意味着内存分配、管理、垃圾收集由虚拟机处理。而在“常规”C++ 中,您必须分配和释放内存。