public static unsafe void InitBlockRefStack(int numBytes, byte value) { byte *stackPtr = stackalloc byte[numBytes]; Unsafe.InitBlock(ref *stackPtr, value, (uint)numBytes); for (int i = 0; i < numBytes; i++) { Assert.Equal(stackPtr[i], value); } }
public static unsafe void InitBlockRefUnmanaged(int numBytes, byte value) { IntPtr allocatedMemory = Marshal.AllocCoTaskMem(numBytes); byte * bytePtr = (byte *)allocatedMemory.ToPointer(); Unsafe.InitBlock(ref *bytePtr, value, (uint)numBytes); for (int i = 0; i < numBytes; i++) { Assert.Equal(bytePtr[i], value); } }
public static void InitBlock(ref byte startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlock(ref startAddress, value, byteCount); }