The Arena Library
0.2.1
|
Source for Arena Library (CBL) More...
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "cbl/assert.h"
#include "cbl/except.h"
#include "arena.h"
Functions | |
arena_t *() | arena_new (void) |
creates a new arena. | |
void() | arena_dispose (arena_t **parena) |
disposes an arena. | |
void *() | arena_alloc (arena_t *arena, size_t n, const char *file, int line) |
allocates storage associated with an arena. | |
void *() | arena_calloc (arena_t *arena, size_t c, size_t n, const char *file, int line) |
allocates zero-filled storage associated with an arena. | |
void() | arena_free (arena_t *arena) |
deallocates all storages belonging to an arena. | |
Variables | |
const except_t | arena_exceptfailNew = { "Arena creation failed" } |
exception for arena creation failure. | |
const except_t | arena_exceptfailAlloc = { "Arena allocation failed" } |
exception for arena memory allocation failure. |
Source for Arena Library (CBL)
void*() arena_alloc | ( | arena_t * | arena, |
size_t | n, | ||
const char * | file, | ||
int | line | ||
) |
allocates storage associated with an arena.
arena_alloc() allocates storage for an arena as malloc() or mem_alloc() does.
Possible exceptions: assert_exceptfail, arena_exceptfailAlloc
Unchecked errors: foreign data structure given for arena
[in,out] | arena | arena for which storage to be allocated |
[in] | n | size of storage requested in bytes |
[in] | file | file name in which storage requested |
[in] | func | function name in which storage requested (if C99 supported) |
[in] | line | line number on which storage requested |
void*() arena_calloc | ( | arena_t * | arena, |
size_t | c, | ||
size_t | n, | ||
const char * | file, | ||
int | line | ||
) |
allocates zero-filled storage associated with an arena.
arena_calloc() does the same as arena_alloc() except that it returns zero-filled storage.
Possible exceptions: assert_exceptfail, arena_exceptfailAlloc
Unchecked errors: foreign data structure given for arena
[in,out] | arena | arena for which zero-filled storage is to be allocated |
[in] | c | number of items to be allocated |
[in] | n | size in bytes for one item |
[in] | file | file name in which storage requested |
[in] | func | function name in which storage requested (if C99 supported) |
[in] | line | line number on which storage requested |
c
* n
in bytes, which allows no overflow in computing the multiplication. Overflow checking is necessary to mimic the behavior of calloc(). void() arena_dispose | ( | arena_t ** | parena | ) |
disposes an arena.
arena_dispose() releases storages belonging to a given arena and disposes it. Do not confuse with arena_free() which gets all storages of an arena deallocated but does not destroy the arena itself.
Note that storages belonging to freelist
is not deallcated by arena_dispose() because it is possibly used by other arenas. Thus, a tool detecting the memory leakage problem might say there is leakage caused by the library, but that is intended not a bug.
Possible exceptions: assert_exceptfail
Unchecked errors: foreign data structure given for parena
[in,out] | parena | pointer to arena to dispose |
void() arena_free | ( | arena_t * | arena | ) |
deallocates all storages belonging to an arena.
arena_free() releases all storages belonging to a given arena.
Possible exceptions: assert_exceptfail
Unchecked errors: foreign data structure given for arena
[in,out] | arena | arena whose storages to be deallocated |
creates a new arena.
arena_new() creates a new arena and initialize it to indicate an empty arena.
Possible exceptions: arena_exceptfailNew
Unchecked errors: none