#include <stddef.h>
#include "cbl/except.h"
Defines | |
#define | ARENA_NEW() (arena_new()) |
allocates a new arena. | |
#define | ARENA_DISPOSE(pa) (arena_dispose(pa)) |
destroys an arena pointed to by pa . | |
#define | ARENA_ALLOC(a, n) (arena_alloc((a), (n), __FILE__, __LINE__)) |
allocates storage whose byte length is n for an arena a . | |
#define | ARENA_CALLOC(a, c, n) (arena_calloc((a), (c), (n), __FILE__, __LINE__)) |
allocates zero-filled storage of the size c * n for an arena a . | |
#define | ARENA_FREE(a) (arena_free(a)) |
deallocates the strorage belonging to an arena a . | |
Typedefs | |
typedef struct arena_t | arena_t |
represents an arena. | |
Functions | |
arena creating functions: | |
arena_t * | arena_new (void) |
creates a new arena. | |
memory allocating/deallocating functions: | |
void * | arena_alloc (arena_t *, size_t n, const char *, int) |
allocates storage associated with an arena. | |
void * | arena_calloc (arena_t *, size_t c, size_t n, const char *, int) |
allocates zero-filled storage associated with an arena. | |
void | arena_free (arena_t *arena) |
deallocates all storages belonging to an arena. | |
arena destroying functions: | |
void | arena_dispose (arena_t **) |
disposes an arena. | |
Variables | |
const except_t | arena_exceptfailNew |
exception for arena creation failure. | |
const except_t | arena_exceptfailAlloc |
exception for arena memory allocation failure. |
Documentation for Arena Library (CBL).
represents an arena.
arena_t
represents an arena to which storages belongs.
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] | 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. So 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 |
arena_t* arena_new | ( | void | ) |
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