Example #1
0
        public unsafe void TempAllocatorCapacityGrowsAndResetsManyAllocs()
        {
            void *[] mem = new void *[4096];

            ExitTempScopesLocally();

            int oldCap = UnsafeUtility.GetTempCapacity();

            for (int i = 0; i < mem.Length; i++)
            {
                UnsafeUtility.EnterTempScope();
                mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp);
            }

            Assert.Greater(UnsafeUtility.GetTempCapacity(), oldCap);

            for (int i = mem.Length - 1; i >= 0; i--)
            {
                UnsafeUtility.Free(mem[i], Collections.Allocator.Temp);
                UnsafeUtility.ExitTempScope();
            }

            Assert.AreEqual(UnsafeUtility.GetTempCapacity(), oldCap);

            EnterTempScopesLocally();
        }
Example #2
0
        public unsafe void TempAllocatorRenestingDoesntLeak()
        {
            void *[] mem          = new void *[4096];
            int      tempUsedBase = UnsafeUtility.GetTempUsed();
            int      tempUsedTop  = -1;
            int      tempCapTop   = -1;

            for (int j = 0; j < 20; j++)
            {
                for (int i = 0; i < mem.Length; i++)
                {
                    UnsafeUtility.EnterTempScope();
                    mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp);
                }

                if (tempUsedTop == -1)
                {
                    tempUsedTop = UnsafeUtility.GetTempUsed();
                    tempCapTop  = UnsafeUtility.GetTempCapacity();
                }
                Assert.AreEqual(tempUsedTop, UnsafeUtility.GetTempUsed());
                Assert.AreEqual(tempCapTop, UnsafeUtility.GetTempCapacity());

                for (int i = mem.Length - 1; i >= 0; i--)
                {
                    UnsafeUtility.Free(mem[i], Collections.Allocator.Temp);
                    UnsafeUtility.ExitTempScope();
                }

                Assert.AreEqual(tempUsedBase, UnsafeUtility.GetTempUsed());
            }
        }
Example #3
0
        public unsafe void TempAllocatorLargerThanDefaultSize()
        {
            const int kSize = 1024 * 1024 * 4;

            ExitTempScopesLocally();

            UnsafeUtility.EnterTempScope();
            int   oldCap    = UnsafeUtility.GetTempCapacity();
            void *largeTemp = UnsafeUtility.Malloc(kSize, 0, Collections.Allocator.Temp);

            Assert.Greater(UnsafeUtility.GetTempCapacity(), oldCap);
            Assert.GreaterOrEqual(UnsafeUtility.GetTempUsed(), kSize);

            UnsafeUtility.Free(largeTemp, Collections.Allocator.Temp);
            UnsafeUtility.ExitTempScope();

            Assert.AreEqual(UnsafeUtility.GetTempCapacity(), oldCap);

            EnterTempScopesLocally();
        }