public static void *Calloc(ref UnmanagedMemoryPool pool) { void *ptr = Alloc(ref pool); Memset(ptr, 0, pool.BlockSize); return(ptr); }
public static void *Alloc(ref UnmanagedMemoryPool pool) { void *pRet = pool.Free; pool.Free = *((byte **)pool.Free); return(pRet); }
public static void Free(ref UnmanagedMemoryPool pool, void *ptr) { if (ptr != null) { void **pHead = (void **)ptr; * pHead = pool.Free; pool.Free = pHead; } }
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); }