nsprpub/lib/ds/plarenas.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef PLARENAS_H
michael@0 7 #define PLARENAS_H
michael@0 8
michael@0 9 PR_BEGIN_EXTERN_C
michael@0 10
michael@0 11 typedef struct PLArenaPool PLArenaPool;
michael@0 12
michael@0 13 /*
michael@0 14 ** Initialize an arena pool with the given name for debugging and metering,
michael@0 15 ** with a minimum gross size per arena of size bytes. The net size per arena
michael@0 16 ** is smaller than the gross size by a header of four pointers plus any
michael@0 17 ** necessary padding for alignment.
michael@0 18 **
michael@0 19 ** Note: choose a gross size that's a power of two to avoid the heap allocator
michael@0 20 ** rounding the size up.
michael@0 21 **/
michael@0 22 PR_EXTERN(void) PL_InitArenaPool(
michael@0 23 PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align);
michael@0 24
michael@0 25 /*
michael@0 26 ** Finish using arenas, freeing all memory associated with them.
michael@0 27 **/
michael@0 28 PR_EXTERN(void) PL_ArenaFinish(void);
michael@0 29
michael@0 30 /*
michael@0 31 ** Free the arenas in pool. The user may continue to allocate from pool
michael@0 32 ** after calling this function. There is no need to call PL_InitArenaPool()
michael@0 33 ** again unless PL_FinishArenaPool(pool) has been called.
michael@0 34 **/
michael@0 35 PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool);
michael@0 36
michael@0 37 /*
michael@0 38 ** Free the arenas in pool and finish using it altogether.
michael@0 39 **/
michael@0 40 PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool);
michael@0 41
michael@0 42 /*
michael@0 43 ** Compact all of the arenas in a pool so that no space is wasted.
michael@0 44 ** NOT IMPLEMENTED. Do not use.
michael@0 45 **/
michael@0 46 PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool);
michael@0 47
michael@0 48 /*
michael@0 49 ** Friend functions used by the PL_ARENA_*() macros.
michael@0 50 **
michael@0 51 ** WARNING: do not call these functions directly. Always use the
michael@0 52 ** PL_ARENA_*() macros.
michael@0 53 **/
michael@0 54 PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb);
michael@0 55
michael@0 56 PR_EXTERN(void *) PL_ArenaGrow(
michael@0 57 PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr);
michael@0 58
michael@0 59 PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
michael@0 60
michael@0 61 /*
michael@0 62 ** memset contents of all arenas in pool to pattern
michael@0 63 */
michael@0 64 PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
michael@0 65
michael@0 66 /*
michael@0 67 ** A function like malloc_size() or malloc_usable_size() that measures the
michael@0 68 ** size of a heap block.
michael@0 69 */
michael@0 70 typedef size_t (*PLMallocSizeFn)(const void *ptr);
michael@0 71
michael@0 72 /*
michael@0 73 ** Measure all memory used by a PLArenaPool, excluding the PLArenaPool
michael@0 74 ** structure.
michael@0 75 */
michael@0 76 PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool(
michael@0 77 const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf);
michael@0 78
michael@0 79 PR_END_EXTERN_C
michael@0 80
michael@0 81 #endif /* PLARENAS_H */

mercurial