private static void SplitTestAssert(int sizeIndex, int userSize, int newUserSize)
        {
            PersistentHeapFreeSpace freeSpace = new PersistentHeapFreeSpace(sizeIndex, sizeIndex + userSize + PersistentHeapSpace.GetUserSizeSize() - 1, 29);

            PersistentHeapUsedSpace usedSpace = freeSpace.Split(newUserSize);

            Assert.AreEqual(newUserSize, freeSpace.UserSize);
            Assert.AreEqual(sizeIndex, freeSpace.SizeIndex);
            Assert.AreEqual(sizeIndex + newUserSize + PersistentHeapSpace.GetUserSizeSize() - 1, freeSpace.EndIndex);

            Assert.AreEqual(userSize - newUserSize - PersistentHeapSpace.GetUserSizeSize(), usedSpace.UserSize);
            Assert.AreEqual(sizeIndex + newUserSize + PersistentHeapSpace.GetUserSizeSize() - 1 + 1, usedSpace.SizeIndex);
        }
Esempio n. 2
0
        public int Allocate(int allocationSize)
        {
            AssertUserSize(allocationSize);
            PersistentHeapFreeSpace freeSpot = GetFreeSpaceThatIsAtLeast(allocationSize);
            PersistentHeapUsedSpace usedSpot;

            if (freeSpot.UserSize > allocationSize)
            {
                usedSpot = freeSpot.Split(allocationSize);
                PutFullSpace(freeSpot);
            }
            else //the freeSpot is the perfect size
            {
                Debug.Assert(freeSpot.UserSize == allocationSize);
                usedSpot = ToUsedSpace(freeSpot);
            }
            PutFullSpace(usedSpot);
            Debug.Assert(usedSpot.UserSize == allocationSize);
            return(usedSpot.StartIndex);
        }