arena.h File Reference

Header for Arena Library (CBL). More...

#include <stddef.h>
#include "cbl/except.h"

Include dependency graph for arena.h:

This graph shows which files directly or indirectly include this file:


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_tarena_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.

Detailed Description

Header for Arena Library (CBL).

Documentation for Arena Library (CBL).


Typedef Documentation

typedef struct arena_t arena_t

represents an arena.

arena_t represents an arena to which storages belongs.


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] 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
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] 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
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. So 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] parena pointer 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] arena arena 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


Generated on Mon Jan 24 01:12:32 2011 for The Arena Library by  doxygen 1.5.8