• Home
  • Raw
  • Download

Lines Matching full:pool

2  * drawElements Memory Pool Library
21 * \brief Memory pool management.
48 * Represent a page of memory allocate by a memory pool.
69 * \brief Memory pool.
71 * A pool of memory from which individual memory allocations can be made.
73 * but rather all of the memory allocated from a pool is freed when the pool
76 * The pools can be arranged into a hierarchy. If a pool with children is
78 * the pool itself.
82 * creating the root pool with the deMemPool_createFailingRoot() function.
92 deMemPool* firstChild; /*!< Pointer to first child pool in linked list. */
93 deMemPool* prevPool; /*!< Previous pool in parent's linked list. */
94 deMemPool* nextPool; /*!< Next pool in parent's linked list. */
106 int lastAllocatedIndex; /*!< Index of last allocated pool (rootPool only). */
165 * \brief Internal function for creating a new memory pool.
166 * \param parent Parent pool (may be null).
167 * \return The created memory pool (or null on failure).
171 deMemPool* pool; in createPoolInternal() local
187 /* Alloc pool from initial page. */ in createPoolInternal()
189 pool = (deMemPool*)(initialPage + 1); in createPoolInternal()
192 memset(pool, 0, sizeof(deMemPool)); in createPoolInternal()
193 pool->currentPage = initialPage; in createPoolInternal()
196 pool->parent = parent; in createPoolInternal()
200 if (parent->firstChild) parent->firstChild->prevPool = pool; in createPoolInternal()
201 pool->nextPool = parent->firstChild; in createPoolInternal()
202 parent->firstChild = pool; in createPoolInternal()
206 pool->util = parent ? parent->util : DE_NULL; in createPoolInternal()
209 pool->allowFailing = parent ? parent->allowFailing : DE_FALSE; in createPoolInternal()
210 deRandom_init(&pool->failRandom, parent ? deRandom_getUint32(&parent->failRandom) : 0x1234abcd); in createPoolInternal()
214 pool->enableDebugAllocs = parent ? parent->enableDebugAllocs : DE_FALSE; in createPoolInternal()
215 pool->debugAllocListHead = DE_NULL; in createPoolInternal()
217 /* Pool allocation index. */ in createPoolInternal()
219 deMemPool* root = pool; in createPoolInternal()
223 if (pool == root) in createPoolInternal()
226 pool->allocIndex = ++root->lastAllocatedIndex; in createPoolInternal()
228 /* \note Put the index of leaking pool here and add a breakpoint to catch leaks easily. */ in createPoolInternal()
229 /* if (pool->allocIndex == 51) in createPoolInternal()
234 return pool; in createPoolInternal()
238 * \brief Create a new root memory pool.
239 * \return The created memory pool (or null on failure).
243 deMemPool* pool = createPoolInternal(DE_NULL); in deMemPool_createRoot() local
244 if (!pool) in deMemPool_createRoot()
248 pool->allowFailing = DE_TRUE; in deMemPool_createRoot()
253 pool->enableDebugAllocs = DE_TRUE; in deMemPool_createRoot()
254 pool->debugAllocListHead = DE_NULL; in deMemPool_createRoot()
262 deMemPoolUtil* utilCopy = DE_POOL_NEW(pool, deMemPoolUtil); in deMemPool_createRoot()
266 deMemPool_destroy(pool); in deMemPool_createRoot()
271 pool->util = utilCopy; in deMemPool_createRoot()
274 return pool; in deMemPool_createRoot()
278 * \brief Create a sub-pool for an existing memory pool.
279 * \return The created memory pool (or null on failure).
283 deMemPool* pool; in deMemPool_create() local
285 pool = createPoolInternal(parent); in deMemPool_create()
286 if (!pool && parent->util) in deMemPool_create()
288 return pool; in deMemPool_create()
292 * \brief Destroy a memory pool.
293 * \param pool Pool to be destroyed.
295 * Frees all the memory allocated from the pool. Also destroyed any child
296 * pools that the pool has (recursively).
298 void deMemPool_destroy (deMemPool* pool) in deMemPool_destroy() argument
305 if (pool->parent) in deMemPool_destroy()
307 deMemPool* root = pool->parent; in deMemPool_destroy()
316 iter = pool->firstChild; in deMemPool_destroy()
324 DE_ASSERT(pool->numChildren == 0); in deMemPool_destroy()
327 if (pool->prevPool) pool->prevPool->nextPool = pool->nextPool; in deMemPool_destroy()
328 if (pool->nextPool) pool->nextPool->prevPool = pool->prevPool; in deMemPool_destroy()
330 if (pool->parent) in deMemPool_destroy()
332 deMemPool* parent = pool->parent; in deMemPool_destroy()
333 if (parent->firstChild == pool) in deMemPool_destroy()
334 parent->firstChild = pool->nextPool; in deMemPool_destroy()
342 if (pool->enableDebugAllocs) in deMemPool_destroy()
344 DebugAlloc* alloc = pool->debugAllocListHead; in deMemPool_destroy()
355 pool->debugAllocListHead = DE_NULL; in deMemPool_destroy()
360 …/* \note Pool itself is allocated from first page, so we must not touch the pool after freeing the… in deMemPool_destroy()
362 MemPage* page = pool->currentPage; in deMemPool_destroy()
375 * \brief Get the number of children for a pool.
376 * \return The number of (immediate) child pools a memory pool has.
378 int deMemPool_getNumChildren (const deMemPool* pool) in deMemPool_getNumChildren() argument
380 return pool->numChildren; in deMemPool_getNumChildren()
384 * \brief Get the number of bytes allocated (by the user) from the pool.
385 * \param pool Pool pointer.
387 * \return The number of bytes allocated by the pool (including child pools
390 int deMemPool_getNumAllocatedBytes (const deMemPool* pool, deBool recurse) in deMemPool_getNumAllocatedBytes() argument
395 for (memPage = pool->currentPage; memPage; memPage = memPage->nextPage) in deMemPool_getNumAllocatedBytes()
401 for (child = pool->firstChild; child; child = child->nextPool) in deMemPool_getNumAllocatedBytes()
408 int deMemPool_getCapacity (const deMemPool* pool, deBool recurse) in deMemPool_getCapacity() argument
413 for (memPage = pool->currentPage; memPage; memPage = memPage->nextPage) in deMemPool_getCapacity()
419 for (child = pool->firstChild; child; child = child->nextPool) in deMemPool_getCapacity()
426 DE_INLINE void* deMemPool_allocInternal (deMemPool* pool, size_t numBytes, deUint32 alignBytes) in deMemPool_allocInternal() argument
428 MemPage* curPage = pool->currentPage; in deMemPool_allocInternal()
431 if (pool->allowFailing) in deMemPool_allocInternal()
433 if ((deRandom_getUint32(&pool->failRandom) & 16383) <= 15) in deMemPool_allocInternal()
439 if (pool->enableDebugAllocs) in deMemPool_allocInternal()
452 header->next = pool->debugAllocListHead; in deMemPool_allocInternal()
453 pool->debugAllocListHead = header; in deMemPool_allocInternal()
476 curPage->nextPage = pool->currentPage; in deMemPool_allocInternal()
477 pool->currentPage = curPage; in deMemPool_allocInternal()
494 * \brief Allocate memory from a pool.
495 * \param pool Memory pool to allocate from.
499 void* deMemPool_alloc (deMemPool* pool, size_t numBytes) in deMemPool_alloc() argument
502 DE_ASSERT(pool); in deMemPool_alloc()
504 ptr = deMemPool_allocInternal(pool, numBytes, DE_POOL_DEFAULT_ALLOC_ALIGNMENT); in deMemPool_alloc()
505 if (!ptr && pool->util) in deMemPool_alloc()
506 pool->util->allocFailCallback(pool->util->userPointer); in deMemPool_alloc()
511 * \brief Allocate aligned memory from a pool.
512 * \param pool Memory pool to allocate from.
517 void* deMemPool_alignedAlloc (deMemPool* pool, size_t numBytes, deUint32 alignBytes) in deMemPool_alignedAlloc() argument
520 DE_ASSERT(pool); in deMemPool_alignedAlloc()
523 ptr = deMemPool_allocInternal(pool, numBytes, alignBytes); in deMemPool_alignedAlloc()
525 if (!ptr && pool->util) in deMemPool_alignedAlloc()
526 pool->util->allocFailCallback(pool->util->userPointer); in deMemPool_alignedAlloc()
531 * \brief Duplicate a piece of memory into a memory pool.
532 * \param pool Memory pool to allocate from.
536 void* deMemPool_memDup (deMemPool* pool, const void* ptr, size_t numBytes) in deMemPool_memDup() argument
538 void* newPtr = deMemPool_alloc(pool, numBytes); in deMemPool_memDup()
545 * \brief Duplicate a string into a memory pool.
546 * \param pool Memory pool to allocate from.
550 char* deMemPool_strDup (deMemPool* pool, const char* str) in deMemPool_strDup() argument
553 char* newStr = (char*)deMemPool_alloc(pool, len+1); in deMemPool_strDup()
560 * \brief Duplicate a string into a memory pool, with a maximum length.
561 * \param pool Memory pool to allocate from.
566 char* deMemPool_strnDup (deMemPool* pool, const char* str, int maxLength) in deMemPool_strnDup() argument
569 char* newStr = (char*)deMemPool_alloc(pool, len + 1); in deMemPool_strnDup()
583 int deMemPool_getMaxNumAllocatedBytes (const deMemPool* pool) in deMemPool_getMaxNumAllocatedBytes() argument
585 DE_ASSERT(pool && !pool->parent); /* must be root */ in deMemPool_getMaxNumAllocatedBytes()
586 return deMax32(pool->maxMemoryAllocated, deMemPool_getNumAllocatedBytes(pool, DE_TRUE)); in deMemPool_getMaxNumAllocatedBytes()
589 int deMemPool_getMaxCapacity (const deMemPool* pool) in deMemPool_getMaxCapacity() argument
591 DE_ASSERT(pool && !pool->parent); /* must be root */ in deMemPool_getMaxCapacity()
592 return deMax32(pool->maxMemoryCapacity, deMemPool_getCapacity(pool, DE_TRUE)); in deMemPool_getMaxCapacity()