ref class VS value class

什么是C++ /CX? 首先要明白它跟C++ 0x/11以及C++ /CLR是完全不同的东西。C++ 0x/11是目前最新的C++标准库,而C++ /CX其实是微软在Win8开发平台下,对C++语言的一种扩展。C++ /CLR是微软为了C++能在.Net下运行,针对CLR,虽然也是对C++的扩展,但它编译后是托管于CLR的,属于Managed C++。而C++ /CX则属于Native C++,它不使用CLR也没有垃圾回收机制。虽然C++ /CX有些新语法特性是直接从/CLR借鉴过来的,但是从底层实现上来看,它们是完全不同的两种扩展。


 

ref class or struct will create reference types. They are created on the managed heap and only references (like pointers when you think of it natively) to those objects are stored and passed.

 

value class or struct are value types. When you pass them around as parameters or as members the whole memory block will be transferred. So you sould use value types only for small data types.

 


ref class是引用类型,存放在堆内存,引用计数开销大
value class是值类型 存放在栈内存,但是作为参数传递时如果数据太大效率低,所以适用于small数据类型

你可能感兴趣的:(Win8开发)