1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/lib/ds/plarenas.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef PLARENAS_H 1.10 +#define PLARENAS_H 1.11 + 1.12 +PR_BEGIN_EXTERN_C 1.13 + 1.14 +typedef struct PLArenaPool PLArenaPool; 1.15 + 1.16 +/* 1.17 +** Initialize an arena pool with the given name for debugging and metering, 1.18 +** with a minimum gross size per arena of size bytes. The net size per arena 1.19 +** is smaller than the gross size by a header of four pointers plus any 1.20 +** necessary padding for alignment. 1.21 +** 1.22 +** Note: choose a gross size that's a power of two to avoid the heap allocator 1.23 +** rounding the size up. 1.24 +**/ 1.25 +PR_EXTERN(void) PL_InitArenaPool( 1.26 + PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align); 1.27 + 1.28 +/* 1.29 +** Finish using arenas, freeing all memory associated with them. 1.30 +**/ 1.31 +PR_EXTERN(void) PL_ArenaFinish(void); 1.32 + 1.33 +/* 1.34 +** Free the arenas in pool. The user may continue to allocate from pool 1.35 +** after calling this function. There is no need to call PL_InitArenaPool() 1.36 +** again unless PL_FinishArenaPool(pool) has been called. 1.37 +**/ 1.38 +PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool); 1.39 + 1.40 +/* 1.41 +** Free the arenas in pool and finish using it altogether. 1.42 +**/ 1.43 +PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool); 1.44 + 1.45 +/* 1.46 +** Compact all of the arenas in a pool so that no space is wasted. 1.47 +** NOT IMPLEMENTED. Do not use. 1.48 +**/ 1.49 +PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool); 1.50 + 1.51 +/* 1.52 +** Friend functions used by the PL_ARENA_*() macros. 1.53 +** 1.54 +** WARNING: do not call these functions directly. Always use the 1.55 +** PL_ARENA_*() macros. 1.56 +**/ 1.57 +PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb); 1.58 + 1.59 +PR_EXTERN(void *) PL_ArenaGrow( 1.60 + PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr); 1.61 + 1.62 +PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark); 1.63 + 1.64 +/* 1.65 +** memset contents of all arenas in pool to pattern 1.66 +*/ 1.67 +PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern); 1.68 + 1.69 +/* 1.70 +** A function like malloc_size() or malloc_usable_size() that measures the 1.71 +** size of a heap block. 1.72 +*/ 1.73 +typedef size_t (*PLMallocSizeFn)(const void *ptr); 1.74 + 1.75 +/* 1.76 +** Measure all memory used by a PLArenaPool, excluding the PLArenaPool 1.77 +** structure. 1.78 +*/ 1.79 +PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool( 1.80 + const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf); 1.81 + 1.82 +PR_END_EXTERN_C 1.83 + 1.84 +#endif /* PLARENAS_H */