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