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