Rel*_*lla 5 .net c# byte visual-c++
我有一个函数想要接收sbyte*buffer如何在C#中从头开始和从现有的byte []创建这样的函数?
// Allocate a new buffer (skip this if you already have one)
byte[] buffer = new byte[256];
unsafe
{
// The "fixed" statement tells the runtime to keep the array in the same
// place in memory (relocating it would make the pointer invalid)
fixed (byte* ptr_byte = &buffer[0])
{
// Cast the pointer to sbyte*
sbyte* ptr_sbyte = (sbyte*) ptr_byte;
// Do your stuff here
}
// The end of the "fixed" block tells the runtime that the original array
// is available for relocation and/or garbage collection again
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4517 次 |
| 最近记录: |