michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef PLARENAS_H michael@0: #define PLARENAS_H michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: typedef struct PLArenaPool PLArenaPool; michael@0: michael@0: /* michael@0: ** Initialize an arena pool with the given name for debugging and metering, michael@0: ** with a minimum gross size per arena of size bytes. The net size per arena michael@0: ** is smaller than the gross size by a header of four pointers plus any michael@0: ** necessary padding for alignment. michael@0: ** michael@0: ** Note: choose a gross size that's a power of two to avoid the heap allocator michael@0: ** rounding the size up. michael@0: **/ michael@0: PR_EXTERN(void) PL_InitArenaPool( michael@0: PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align); michael@0: michael@0: /* michael@0: ** Finish using arenas, freeing all memory associated with them. michael@0: **/ michael@0: PR_EXTERN(void) PL_ArenaFinish(void); michael@0: michael@0: /* michael@0: ** Free the arenas in pool. The user may continue to allocate from pool michael@0: ** after calling this function. There is no need to call PL_InitArenaPool() michael@0: ** again unless PL_FinishArenaPool(pool) has been called. michael@0: **/ michael@0: PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool); michael@0: michael@0: /* michael@0: ** Free the arenas in pool and finish using it altogether. michael@0: **/ michael@0: PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool); michael@0: michael@0: /* michael@0: ** Compact all of the arenas in a pool so that no space is wasted. michael@0: ** NOT IMPLEMENTED. Do not use. michael@0: **/ michael@0: PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool); michael@0: michael@0: /* michael@0: ** Friend functions used by the PL_ARENA_*() macros. michael@0: ** michael@0: ** WARNING: do not call these functions directly. Always use the michael@0: ** PL_ARENA_*() macros. michael@0: **/ michael@0: PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb); michael@0: michael@0: PR_EXTERN(void *) PL_ArenaGrow( michael@0: PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr); michael@0: michael@0: PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark); michael@0: michael@0: /* michael@0: ** memset contents of all arenas in pool to pattern michael@0: */ michael@0: PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern); michael@0: michael@0: /* michael@0: ** A function like malloc_size() or malloc_usable_size() that measures the michael@0: ** size of a heap block. michael@0: */ michael@0: typedef size_t (*PLMallocSizeFn)(const void *ptr); michael@0: michael@0: /* michael@0: ** Measure all memory used by a PLArenaPool, excluding the PLArenaPool michael@0: ** structure. michael@0: */ michael@0: PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool( michael@0: const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* PLARENAS_H */