Пример #1
0
        static rcSpan allocSpan(rcHeightfield hf)
        {
            // If running out of memory, allocate new page and update the freelist.
            if (hf.freelist == null || hf.freelist.next == null)
            {
                // Create new page.
                // Allocate memory for the new pool.
                rcSpanPool pool = new rcSpanPool();
                pool.next = null;
                // Add the pool into the list of pools.
                pool.next = hf.pools;
                hf.pools  = pool;
                // Add new items to the free list.
                rcSpan?freelist = hf.freelist;
                //rcSpan head = pool.items[0];
                //rcSpan it = pool.items[RC_SPANS_PER_POOL];
                int itIndex = RC_SPANS_PER_POOL;
                do
                {
                    --itIndex;
                    pool.items[itIndex].next = freelist;
                    freelist = pool.items[itIndex];
                }while (itIndex != 0);
                hf.freelist = pool.items[itIndex];
            }

            // Pop item from in front of the free list.
            rcSpan it = hf.freelist;

            hf.freelist = hf.freelist.next;
            return(it);
        }
Пример #2
0
    static rcSpan allocSpan(rcHeightfield hf)
    {
        // If running out of memory, allocate new page and update the freelist.
        if (hf.freelist == null || hf.freelist.next == null)
        {
            // Create new page.
            // Allocate memory for the new pool.
            //rcSpanPool* pool = (rcSpanPool*)rcAlloc(sizeof(rcSpanPool), RC_ALLOC_PERM);
            rcSpanPool pool = new rcSpanPool();
            if (pool == null)
                return null;
            pool.next = null;
            // Add the pool into the list of pools.
            pool.next = hf.pools;
            hf.pools = pool;
            // Add new items to the free list.
            rcSpan freelist = hf.freelist;
            //rcSpan head = pool.items[0];
            //rcSpan it = pool.items[RC_SPANS_PER_POOL];
            int itIndex = RC_SPANS_PER_POOL;
            do
            {
                --itIndex;
                pool.items[itIndex].next = freelist;
                freelist = pool.items[itIndex];
            }
            while (itIndex != 0);
            hf.freelist = pool.items[itIndex];
        }

        // Pop item from in front of the free list.
        rcSpan it = hf.freelist;
        hf.freelist = hf.freelist.next;
        return it;
    }