1 回答

TA貢獻1804條經驗 獲得超3個贊
嘗試以下:
MemoryStream stream = new MemoryStream();
byte[] buffer = new byte[70 * 2 * sizeof(int)];
stream.Read(buffer, 0, 70 * 2 * sizeof(int));
for (int i = 0; i< 70; i++)
{
for (int j = 0; j < 2; j++)
{
Console.WriteLine(BitConverter.ToUInt32(buffer,(i * 2 * sizeof(int)) + (j * sizeof(int))));
}
}
IntPtr bufferPtr = Marshal.AllocHGlobal(BUFFER_SIZE);
//you need to allocate memory before calling the routing
byte[] buffer = new byte[BUFFER_SIZE];
Marshal.Copy(bufferPtr, buffer, 0, BUFFER_SIZE);
for (int i = 0; i < 70; i++)
{
for (int j = 0; j < 2; j++)
{
Console.WriteLine(BitConverter.ToUInt32(buffer, (i * 2 * sizeof(int)) + (j * sizeof(int))));
}
}
//method 2
int[,] array = new int[40, 2];
IntPtr bufferPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(array));
//call routine then you code below to fill managed memory.
Marshal.PtrToStructure(bufferPtr2, array);
- 1 回答
- 0 關注
- 171 瀏覽
添加回答
舉報