예제 #1
0
        static void CreatePage(Native aItemSize)
        {
            if (aItemSize == 0)
            {
                throw new Exception("ItemSize cannot be 0.");
            }
            else if (aItemSize % sizeof(Native) != 0)
            {
                throw new Exception("Item size must be word aligned.");
            }
            else if (mMaxItemSize == 0)
            {
                throw new Exception("SMT is not initialized.");
            }
            else if (aItemSize > mMaxItemSize)
            {
                throw new Exception("Cannot allocate more than MaxItemSize in SmallHeap.");
            }

            var xPtr = (Native *)RAT.Alloc(RAT.PageType.HeapSmall);

            *xPtr = 0;
            for (void **p = mSMT + aItemSize; ; p--)
            {
                // TODO - Make a free list, put a ptr in item header and first page header - how to keep compact?
            }
            // Header
            // Ptr to next page of same size

            // Each Item
            //xPtr[0] = aSize; // Actual data size
            //xPtr[1] = 0; // Ref count
            //xPtr[2] = 0; // Ptr to first
        }
예제 #2
0
        static void InitSMT(Native aMaxItemSize)
        {
            mMaxItemSize = aMaxItemSize;
            Native xPageCount = mMaxItemSize * (Native)sizeof(void *) / RAT.PageSize;

            mSMT = (void **)RAT.Alloc(RAT.PageType.HeapSmall, xPageCount);
        }
예제 #3
0
        static public byte *Alloc(Native aSize)
        {
            Native xPages = (Native)((aSize + PrefixBytes) / RAT.PageSize) + 1;
            var    xPtr   = (Native *)RAT.Alloc(RAT.PageType.HeapLarge, xPages);

            xPtr[0] = xPages * RAT.PageSize - PrefixBytes; // Allocated data size
            xPtr[1] = aSize;                               // Actual data size
            xPtr[2] = 0;                                   // Ref count
            xPtr[3] = 0;                                   // Ptr to first

            return((byte *)xPtr + PrefixBytes);
        }