[英]C# interop : handling pointer-array in unmanaged struct
I'm wrapping a few calls to the unmanaged Aubio library dll (Aubio.org), and I'm wondering what a good way is to deal with the Aubio samplebuffer. 我正在包装对非托管Aubio库dll(Aubio.org)的一些调用,我想知道处理Aubio样本缓冲区的好方法是什么。
It's defined like this : 它的定义如下:
// Buffer for real values
struct _fvec_t {
uint length; // length of buffer
uint channels; // number of channels
float **data; // data array of size [length] * [channels]
};
Aubio creates the struct for me with the datamembers set up correctly, so I get an IntPtr. Aubio使用正确设置的数据成员为我创建了结构,因此我得到了IntPtr。 I need to read/write to the data pointer(s) from my C# code. 我需要从C#代码读取/写入数据指针。
for (int chan_idx = 0; chan_idx < my_fvec.channels; ++chan_idx)
for (int i=0; i<something; i++)
my_fvec.data[chan_idx][i] = SomeRandomValue();
What is the correct way to 'map' a C# struct to the fvec_t type so I can access the data member properly to read/write to it ? 将C#结构“映射”到fvec_t类型的正确方法是什么,以便我可以正确访问数据成员以对其进行读写?
(Or should I use Marshal.Copy,and how do I do that with the array-of-pointers ?) (或者我应该使用Marshal.Copy,以及如何使用指针数组?)
I'd imagine you could define a managed struct and PtrToStructure what you have, modify, then StructureToPtr (back to the same location), but it might be just as simple, since the memory is already allocated and all, to just read out the intptr's for the arrays and then write the float arrays to them with Copy: 我以为您可以定义托管结构和PtrToStructure所拥有的内容,然后进行修改,然后再修改StructureToPtr(返回相同的位置),但这可能就这么简单,因为已经分配了内存,并且所有这些都可以读出数组的intptr,然后使用Copy将float数组写入它们:
http://msdn.microsoft.com/en-us/library/ez2e4559.aspx http://msdn.microsoft.com/en-us/library/ez2e4559.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.