Lines Matching refs:arena
4 /* A simple arena block structure.
29 /* An arena maintains a singly-linked, NULL-terminated list of
30 * all blocks owned by the arena. These are linked via the
41 /* The arena manages two kinds of memory, blocks of raw memory
43 when the arena is freed.
47 /* Pointer to the first block allocated for the arena, never NULL.
48 It is used only to find the first block when the arena is
61 pointers associated with this arena. They will be DECREFed
62 when the arena is freed.
131 PyArena* arena = (PyArena *)PyMem_Malloc(sizeof(PyArena));
132 if (!arena)
135 arena->a_head = block_new(DEFAULT_BLOCK_SIZE);
136 arena->a_cur = arena->a_head;
137 if (!arena->a_head) {
138 PyMem_Free((void *)arena);
141 arena->a_objects = PyList_New(0);
142 if (!arena->a_objects) {
143 block_free(arena->a_head);
144 PyMem_Free((void *)arena);
148 arena->total_allocs = 0;
149 arena->total_size = 0;
150 arena->total_blocks = 1;
151 arena->total_block_size = DEFAULT_BLOCK_SIZE;
152 arena->total_big_blocks = 0;
154 return arena;
158 _PyArena_Free(PyArena *arena)
160 assert(arena);
165 arena->total_allocs, arena->total_size, arena->total_blocks,
166 arena->total_block_size, arena->total_big_blocks,
167 PyList_Size(arena->a_objects));
170 block_free(arena->a_head);
173 assert(arena->a_objects->ob_refcnt == 1);
176 Py_DECREF(arena->a_objects);
177 PyMem_Free(arena);
181 _PyArena_Malloc(PyArena *arena, size_t size)
183 void *p = block_alloc(arena->a_cur, size);
187 arena->total_allocs++;
188 arena->total_size += size;
191 if (arena->a_cur->ab_next) {
192 arena->a_cur = arena->a_cur->ab_next;
194 arena->total_blocks++;
195 arena->total_block_size += arena->a_cur->ab_size;
196 if (arena->a_cur->ab_size > DEFAULT_BLOCK_SIZE)
197 ++arena->total_big_blocks;
204 _PyArena_AddPyObject(PyArena *arena, PyObject *obj)
206 int r = PyList_Append(arena->a_objects, obj);