Beispiel #1
0
        public static void *Calloc(ref UnmanagedMemoryPool pool)
        {
            void *ptr = Alloc(ref pool);

            Memset(ptr, 0, pool.BlockSize);

            return(ptr);
        }
Beispiel #2
0
        public static void *Alloc(ref UnmanagedMemoryPool pool)
        {
            void *pRet = pool.Free;

            pool.Free = *((byte **)pool.Free);

            return(pRet);
        }
Beispiel #3
0
 public static void Free(ref UnmanagedMemoryPool pool, void *ptr)
 {
     if (ptr != null)
     {
         void **pHead = (void **)ptr;
         *      pHead = pool.Free;
         pool.Free = pHead;
     }
 }
Beispiel #4
0
        public static UnmanagedMemoryPool AllocPool(int blockSize, int numBlocks)
        {
            Debug.Assert(blockSize >= MinimumPoolBlockSize);
            Debug.Assert(numBlocks > 0);

            blockSize = ((blockSize + 7) & (-8));

            UnmanagedMemoryPool pool = new UnmanagedMemoryPool();

            pool.Free      = null;
            pool.NumBlocks = numBlocks;
            pool.BlockSize = blockSize;

            pool.Alloc = (byte *)Alloc(blockSize * numBlocks);

            FreeAll(&pool);

            return(pool);
        }