[C#]C++/CLI中^的含义
2024-10-20 16:42:09
例子
// here normal pointer
P* ptr = new P; // usual pointer allocated on heap
P& nat = *ptr; // object on heap bind to native object
//.. here CLI managed
MO^ mngd = gcnew MO; // allocate on CLI heap
MO% rr = *mngd; // object on CLI heap reference to gc-lvalue
解释:在C++/CLI中,^指向托管的对象,对象的内存回收由CLR垃圾回收器自动管理,当然我们也可以用*来创建手动管理内存对象。
参考几个Stackoverflow上的答案:
It means that this is a reference to a managed object vs. a regular C++ pointer. Objects behind such references are managed by the runtime and can be relocated in the memory. They are also garbage-collected automatically.
When you allocated managed memory, that memory can be moved around by the garbage collector. The ^ operator is a pointer for managed memory, that continues to point to the correct place even if the garbage collector moves the object it points to.
最新文章
- 冰冻三尺非一日之寒--web框架Django
- 第23章 排序算法(包括merge等)
- jQuery动态加载脚本 $.getScript();
- 使用 Override 和 New 关键字进行版本控制
- C++ “读取位置 0x****** 时发生访问冲突”的可能原因
- linux和MAC下静态库.a文件合并
- Python学习笔记——几种数据类型
- [SQL学习笔记][用exists代替全称量词 ]
- [C#参考]主线程和子线程之间的参数传递
- 转:C++中引用传递与指针传递区别
- bootstrap datatable项目封装支持单选多选
- 矩阵快速幂---BestCoder Round#8 1002
- webApi签名验证
- multipath多路径实验02-配置多路径软件
- 小账本APP——软件项目风险管理及解决办法案例
- Protege4.3 添加Rules 栏
- CentOS6/7快捷使用gcc5
- std::string 用法总结
- 会话的保持和form表单
- HTML语言和CSS开发