env_alloc.c File Reference

#include "Envision/env_alloc.h"
#include "Envision/env_log.h"
Include dependency graph for env_alloc.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  free_list_node
 Free-node class for free-list memory pools. More...
struct  free_list
 Base class for maintaining a free-list memory pool. More...
struct  alloc_info
 Auxiliary information about an aligned memory allocation. More...
struct  aligned_alloc
 Allocate memory that is aligned on an NALIGN-byte boundary. More...

Defines

#define NALIGN   ((env_size_t)((4*sizeof(void*)) > 16 ? (4*sizeof(void*)) : 16))

Typedefs

typedef char sizeof_alloc_info_must_equal_NALIGN [(sizeof(struct alloc_info)==NALIGN)?1:-1]

Functions

static void env_free_list_init (struct free_list *p, env_size_t size_check)
static void * env_free_list_allocate (struct free_list *p, env_size_t bytes)
 Allocate space for a new object.
static void env_free_list_deallocate (struct free_list *p, void *space)
 Return an object to the free list.
static void env_free_list_cleanup (struct free_list *p)
static void env_aligned_alloc_init (struct aligned_alloc *p)
static void env_aligned_alloc_get_stats (const struct aligned_alloc *p, struct env_alloc_stats *stats)
static void * env_aligned_alloc_allocate (struct aligned_alloc *p, env_size_t user_nbytes)
static void env_aligned_alloc_deallocate (struct aligned_alloc *p, void *user_addr)
static void env_aligned_alloc_cleanup (struct aligned_alloc *p)
void * env_allocate (env_size_t user_nbytes)
 Allocate nbytes of memory, throwing an exception in case of failure.
void env_deallocate (void *mem)
 Deallocate the given memory region.
void env_allocation_get_stats (struct env_alloc_stats *stats)
 Get current memory allocator stats.
void env_allocation_init (env_alloc_func *alloc_func, env_dealloc_func *dealloc_func)
 Initialize memory allocator.
void env_allocation_cleanup (void)
 Release any cached memory blocks.
void env_allocation_init_mutex_funcs (void *userdata, env_alloc_mutex_func *mutex_acquire, env_alloc_mutex_func *mutex_release)
 Install callbacks to provide thread-safety if desired.

Variables

static env_alloc_func * g_raw_alloc = 0
static env_dealloc_func * g_raw_dealloc = 0
static void * g_mutex_userdata = 0
static env_alloc_mutex_func * g_mutex_acquire = 0
static env_alloc_mutex_func * g_mutex_release = 0
struct aligned_alloc g_alloc

Detailed Description

memory allocation routines for 16-byte alignment

Definition in file env_alloc.c.


Function Documentation

void* env_allocate ( env_size_t  user_nbytes  ) 

Allocate nbytes of memory, throwing an exception in case of failure.

Definition at line 345 of file env_alloc.c.

Referenced by env_mt_chan_orientation(), env_mt_motion_channel_input_and_consume_pyr(), env_pyr_init(), and env_stdio_parse_rgb().

void env_allocation_cleanup ( void   ) 

Release any cached memory blocks.

Definition at line 386 of file env_alloc.c.

Referenced by EnvVisualCortexBase::~EnvVisualCortexBase().

void env_allocation_get_stats ( struct env_alloc_stats stats  ) 

Get current memory allocator stats.

Definition at line 365 of file env_alloc.c.

Referenced by EnvVisualCortexBase::stop2().

void env_allocation_init ( env_alloc_func *  alloc_func,
env_dealloc_func *  dealloc_func 
)

Initialize memory allocator.

Parameters:
alloc_func pointer to some function that allocates raw memory (e.g. something that wraps malloc())
dealloc_func pointer to some function that deallocates raw memory (e.g. free())

Definition at line 373 of file env_alloc.c.

Referenced by EnvVisualCortexBase::start1().

void env_allocation_init_mutex_funcs ( void *  userdata,
env_alloc_mutex_func *  mutex_acquire,
env_alloc_mutex_func *  mutex_release 
)

Install callbacks to provide thread-safety if desired.

Parameters:
mutex_acquire this function will be called at the beginning of every env_allocate(), env_deallocate(), env_allocation_get_stats(), env_allocation_init(), and env_allocation_cleanup() call
mutex_release this function will be called at the end of every such call

It is not necessary to install any callbacks in a program where env_allocate() and env_deallocate() are always called from just a single thread; but any program that might use those functions concurrently from multiple threads must install mutex functions here.

Definition at line 394 of file env_alloc.c.

Referenced by env_init_pthread_alloc().

void env_deallocate ( void *  mem  ) 

Deallocate the given memory region.

Definition at line 354 of file env_alloc.c.

Referenced by env_mt_chan_orientation(), and env_mt_motion_channel_input_and_consume_pyr().

static void* env_free_list_allocate ( struct free_list p,
env_size_t  bytes 
) [static]

Allocate space for a new object.

If there are chunks available in the free list, one of those is returned; otherwise new memory is allocated with (*g_raw_alloc).

Definition at line 129 of file env_alloc.c.

static void env_free_list_deallocate ( struct free_list p,
void *  space 
) [static]

Return an object to the free list.

Definition at line 149 of file env_alloc.c.

Generated on Sun May 8 08:11:50 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3