The Arena Library  0.2.1
Functions | Variables
arena.c File Reference

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"
Include dependency graph for arena.c:

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.

Detailed Description

Source for Arena Library (CBL)


Function Documentation

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

Parameters:
[in,out]arenaarena for which storage to be allocated
[in]nsize of storage requested in bytes
[in]filefile name in which storage requested
[in]funcfunction name in which storage requested (if C99 supported)
[in]lineline number on which storage requested
Returns:
storage allocated for given arena

Here is the caller graph for this function:

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

Parameters:
[in,out]arenaarena for which zero-filled storage is to be allocated
[in]cnumber of items to be allocated
[in]nsize in bytes for one item
[in]filefile name in which storage requested
[in]funcfunction name in which storage requested (if C99 supported)
[in]lineline number on which storage requested
Returns:
zero-filled storage allocated for arena
Todo:
Some improvements are possible and planned:
  • the C standard requires calloc() return a null pointer if it cannot allocates storage of the size c * n in bytes, which allows no overflow in computing the multiplication. Overflow checking is necessary to mimic the behavior of calloc().

Here is the call graph for this function:

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

Parameters:
[in,out]parenapointer to arena to dispose
Returns:
nothing

Here is the call graph for this function:

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

Parameters:
[in,out]arenaarena whose storages to be deallocated
Returns:
nothing

Here is the caller graph for this function:

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

Returns:
new arena created
 All Files Functions Variables Typedefs Defines