Example #1
0
        public void AlignedAllocLessThanVoidPtrAlignmentTest()
        {
            void *ptr = NativeMemory.AlignedAlloc(1, 1);

            Assert.True(ptr != null);
            NativeMemory.AlignedFree(ptr);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public void AlignedAllocTest(uint alignment)
        {
            void *ptr = NativeMemory.AlignedAlloc(1, alignment);

            Assert.True(ptr != null);
            Assert.True((nuint)ptr % alignment == 0);

            NativeMemory.AlignedFree(ptr);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 public void AlignedFreeTest()
 {
     // This should not throw
     NativeMemory.AlignedFree(null);
 }
 private static void _aligned_free(void *_Block)
 {
     NativeMemory.AlignedFree(_Block);
 }