예제 #1
0
        public void AllocateAlignedMemory(int alignment, int size)
        {
            var isNotWindows          = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
            var alignmentIsPowerOfTwo = IsPowerOfTwo((UInt64)alignment);

            if (!alignmentIsPowerOfTwo || (isNotWindows && (alignment % IntPtr.Size) != 0))
            {
                Assert.Throws <ArgumentException>(() => MarshalEx.AllocHGlobalAligned(size, alignment));
            }
            else
            {
                Assert.True(MarshalEx.AllocHGlobalAligned(size, alignment).ToInt64() % alignment == 0);
            }
        }
예제 #2
0
        public void FreeAligned()
        {
            var aligned = MarshalEx.AllocHGlobalAligned(16, 64);

            MarshalEx.FreeHGlobalAligned(aligned);
        }