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:


Data Structures

struct  arena_t
union  align
union  header

Defines

#define MULTIPLE(x, y)   ((((x)+(y)-1)/(y)) * (y))
#define ALIGNED(p)   ((uintptr_t)(p) % sizeof(union align) == 0)
#define FREE_THRESHOLD   10

Typedefs

typedef unsigned long uintptr_t

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] 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:31 2011 for The Arena Library by  doxygen 1.5.8