Exemplo n.º 1
0
        public void CouldAllocFree()
        {
            var p = Mem.Malloc((UIntPtr)123);

            p = Mem.Realloc(p, (UIntPtr)456);
            p = Mem.Reallocf(p, (UIntPtr)789);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.Calloc((UIntPtr)1, (UIntPtr)2);
            Assert.IsTrue(p != null);
            Console.WriteLine(Mem.UsableSize(p));
            p = Mem.Recalloc(p, (UIntPtr)10, (UIntPtr)3);
            Assert.IsTrue(p != null);
            Console.WriteLine(Mem.UsableSize(p));
            p = Mem.Expand(p, (UIntPtr)Mem.UsableSize(p));
            Assert.IsTrue(p != null);
            Mem.Free(p);

            Mem.Collect(false);

            p = Mem.MallocSmall((UIntPtr)42);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.ZallocSmall((UIntPtr)42);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.Zalloc((UIntPtr)42000);
            Assert.IsTrue(p != null);
            p = Mem.Rezalloc(p, (UIntPtr)100000);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.Mallocn((UIntPtr)10, (UIntPtr)20);
            Assert.IsTrue(p != null);
            p = Mem.Reallocn(p, (UIntPtr)100, (UIntPtr)20);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            Mem.Collect(true);

            p = Mem.MallocAligned((UIntPtr)(16 * 17), (UIntPtr)16);
            Assert.IsTrue(p != null);
            Console.WriteLine(Mem.UsableSize(p));
            p = Mem.ReallocAligned(p, (UIntPtr)(16 * 30), (UIntPtr)16);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.MallocAlignedAt((UIntPtr)(3 + 16 * 17), (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            p = Mem.ReallocAlignedAt(p, (UIntPtr)(3 + 16 * 34), (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.ZallocAligned((UIntPtr)(16 * 17), (UIntPtr)16);
            Assert.IsTrue(p != null);
            p = Mem.RezallocAligned(p, (UIntPtr)(16 * 30), (UIntPtr)16);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.ZallocAlignedAt((UIntPtr)(3 + 16 * 17), (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            p = Mem.RezallocAlignedAt(p, (UIntPtr)(3 + 16 * 34), (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.CallocAligned((UIntPtr)17, (UIntPtr)16, (UIntPtr)16);
            Assert.IsTrue(p != null);
            p = Mem.RecallocAligned(p, (UIntPtr)34, (UIntPtr)16, (UIntPtr)16);
            Assert.IsTrue(p != null);
            Mem.Free(p);

            p = Mem.CallocAlignedAt((UIntPtr)17, (UIntPtr)16, (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            p = Mem.RecallocAlignedAt(p, (UIntPtr)34, (UIntPtr)16, (UIntPtr)16, (UIntPtr)3);
            Assert.IsTrue(p != null);
            Mem.Free(p);
        }