public void AlignedAllocLessThanVoidPtrAlignmentTest() { void *ptr = NativeMemory.AlignedAlloc(1, 1); Assert.True(ptr != null); NativeMemory.AlignedFree(ptr); }
public void AlignedAllocZeroSizeTest() { void *ptr = NativeMemory.AlignedAlloc(0, (uint)sizeof(nuint)); Assert.True(ptr != null); Assert.True((nuint)ptr % (uint)sizeof(nuint) == 0); NativeMemory.AlignedFree(ptr); }
public void AlignedReallocNullPtrTest() { void *ptr = NativeMemory.AlignedRealloc(null, 1, (uint)sizeof(nuint)); Assert.True(ptr != null); Assert.True((nuint)ptr % (uint)sizeof(nuint) == 0); NativeMemory.AlignedFree(ptr); }
public void AlignedAllocTest(uint alignment) { void *ptr = NativeMemory.AlignedAlloc(1, alignment); Assert.True(ptr != null); Assert.True((nuint)ptr % alignment == 0); NativeMemory.AlignedFree(ptr); }
public void AlignedReallocZeroAlignmentTest() { void *ptr = NativeMemory.AlignedAlloc(1, (uint)sizeof(nuint)); Assert.True(ptr != null); Assert.True((nuint)ptr % (uint)sizeof(nuint) == 0); Assert.Throws <ArgumentException>(() => NativeMemory.AlignedRealloc(ptr, (uint)sizeof(nuint), 0)); NativeMemory.AlignedFree(ptr); }
public void ZeroMemoryWithSizeEqualTo0ShouldNoOpTest(int offset) { byte *ptr = (byte *)NativeMemory.AlignedAlloc(512, 8); Assert.True(ptr != null); Assert.True((nuint)ptr % 8 == 0); new Span <byte>(ptr, 512).Fill(0b10101010); NativeMemory.ZeroMemory(ptr + offset, 0); Assert.Equal(-1, new Span <byte>(ptr, 512).IndexOfAnyExcept((byte)0b10101010)); NativeMemory.AlignedFree(ptr); }
public void ZeroMemoryTest(int size, int offset) { byte *ptr = (byte *)NativeMemory.AlignedAlloc((nuint)(size + offset), 8); Assert.True(ptr != null); Assert.True((nuint)ptr % 8 == 0); new Span <byte>(ptr, size + offset).Fill(0b10101010); NativeMemory.ZeroMemory(ptr + offset, (nuint)size); Assert.Equal(-1, new Span <byte>(ptr + offset, size).IndexOfAnyExcept((byte)0)); NativeMemory.AlignedFree(ptr); }
public void AlignedReallocSmallerToLargerTest() { void *ptr = NativeMemory.AlignedAlloc(16, 16); Assert.True(ptr != null); Assert.True((nuint)ptr % 16 == 0); for (int i = 0; i < 16; i++) { ((byte *)ptr)[i] = (byte)i; } void *newPtr = NativeMemory.AlignedRealloc(ptr, 32, 16); Assert.True(newPtr != null); Assert.True((nuint)newPtr % 16 == 0); for (int i = 0; i < 16; i++) { Assert.True(((byte *)newPtr)[i] == i); } NativeMemory.AlignedFree(newPtr); }
public void ZeroMemoryWithExactRangeTest(int size, int offset) { int headLength = offset; int bodyLength = size; int tailLength = 512 - headLength - bodyLength; int headOffset = 0; int bodyOffset = headLength; int tailOffset = headLength + bodyLength; byte *ptr = (byte *)NativeMemory.AlignedAlloc(512, 8); Assert.True(ptr != null); Assert.True((nuint)ptr % 8 == 0); new Span <byte>(ptr, 512).Fill(0b10101010); NativeMemory.ZeroMemory(ptr + bodyOffset, (nuint)bodyLength); Assert.Equal(-1, new Span <byte>(ptr + headOffset, headLength).IndexOfAnyExcept((byte)0b10101010)); Assert.Equal(-1, new Span <byte>(ptr + bodyOffset, bodyLength).IndexOfAnyExcept((byte)0)); Assert.Equal(-1, new Span <byte>(ptr + tailOffset, tailLength).IndexOfAnyExcept((byte)0b10101010)); NativeMemory.AlignedFree(ptr); }
public void AlignedFreeTest() { // This should not throw NativeMemory.AlignedFree(null); }
private static void _aligned_free(void *_Block) { NativeMemory.AlignedFree(_Block); }