我需要别针吗? [英] Do I need to pin?
本文介绍了我需要别针吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我拥有不受控制的功能:
I have unmanaged funciton:
int fu1(char ** buf);
int fu1(char** buf);
我在C#中使用以下代码:
I use following in C#:
static extern int fu1(ref IntPtr buf);
static extern int fu1(ref IntPtr buf);
我这样称呼它:
byte [] mBuf;
IntPtr temp = IntPtr();
int size = fu1(ref temp);
mDuf =新的byte [size];
元帅. Copy(temp,mBuf,0,size);
这很好用,但问题是-我需要固定温度吗?
byte[] mBuf;
IntPtr temp = IntPtr();
int size = fu1(ref temp);
mDuf = new byte[size];
Marshal.Copy(temp, mBuf, 0, size);
This works fine, but the question is - do I need to pin temp?
推荐答案
否 由于temp是一个IntPtr,因此您只是传递了一个内存地址,该地址(大概)是由非托管代码设置的.
No. Since temp is an IntPtr, you're just passing around a memory address, which is (presumably) being set by unmanaged code.
这篇关于我需要别针吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文