GCHandle :: Alloc是否会分配新内存? [英] Does GCHandle::Alloc alocate new memory?

查看:115
本文介绍了GCHandle :: Alloc是否会分配新内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个CLI C ++命令如何工作 -

How does this CLI C++ command work-

GCHandle my_Handle = GCHandle::Alloc(dBlob, GCHandleType::Pinned);

Alloc功能是否正常复制指向的对象by  dBlob
到一个新的记忆中  my_Handle
现在指向新的托管内存,或者它指向原始位置  dBlob
位置(也就是说,如果我改变
my_Handle
是否也在原始位置更改
dBlob
? )

Does the Alloc function copy the object pointed by dBlob into a new memeory and my_Handle now points to that new managed memory, or does it point to the original location of dBlob location (aka, if i change my_Handle does it also change dBlob in the original location or not?)




推荐答案

根据文档, Alloc 分配(创建)句柄,而不是内存。

According to documentation, Alloc allocates (creates) the handle, not the memory.

如果固定,你可以使用 GCHandle :: AddrOfPinnedObject 以获取内存的地址。

If pinned, you can use GCHandle::AddrOfPinnedObject to get the address of the memory.

如果没有固定,垃圾收集器可以移动对象在其运作期间对象被移动,分配的
GCHandle 仍然有效。

If not pinned, the object can be moved by Garbage Collector during its operations. When the object is moved, the allocated GCHandle remains valid.

如果存在关联的
GCHandle ,垃圾收集器不会销毁该对象正常固定类型。

The object is not destroyed by Garbage Collector if there is an associated GCHandle of Normal or Pinned type.


这篇关于GCHandle :: Alloc是否会分配新内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆