/mnt/hgfs/jamie_On_My_Mac/store/version_control/svn/integralive/library/trunk/src/memory.c File Reference

#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include "Integra/integra_error.h"
#include "memory.h"
#include "debug.h"
#include "globals.h"

Functions

void * ntg_calloc (size_t nmemb, size_t size)
 Wrapper for glibc calloc function.
void * ntg_malloc (size_t size)
 Wrapper for glibc malloc function.
void * ntg_alloc (size_t nmemb, size_t size, int allocation_type)
 Function that gets wrapped by ntg_malloc() and ntg_calloc().
int ntg_free (void *ptr)
 Wrapper for glibc free function.
void * ntg_realloc (void *ptr, size_t size)
 Wrapper for glibc realloc function.
void * ntg_make_alias (void *ptr)
 Return a pointer alias and increment the reference count of the pointed-to memory.
int ntg_kill_alias (void *ptr)
 De-reference and pointer alias.
ntg_memkeeperntg_find_memkeeper (void *ptr)
 Helper function to locate a pointer in the allocation table.
int ntg_sweep_allocation_table ()
 Sweep allocation table and print details.

Function Documentation

void* ntg_alloc ( size_t  nmemb,
size_t  size,
int  allocation_type 
)

Function that gets wrapped by ntg_malloc() and ntg_calloc().

This function handles the actual memory allocation as well some rather crude book-keeping. ntg_malloc() and ntg_calloc() are set up as wrappers, avoiding code duplication at the expense of efficiency.

Parameters:
size_t nmemb The number of elements to allocate.
size_t size The size in bytes of each element. This will be 0 if allocation type is NTG_MALLOC.
int allocation_type The id of the memory allocation callback as defined in the ntg_allocation_types_ enumeration

References ntg_allocation_table_::allocation_count, allocation_table, ntg_memkeeper_::bytes, DB_MEMORY, DEBUG_POST(), ntg_allocation_table_::end, ntg_memkeeper_::index, ntg_memkeeper_::mem, ntg_memkeeper_::next, NTG_MALLOC, ntg_memkeeper_::prev, ntg_memkeeper_::reference_count, and ntg_allocation_table_::start.

Referenced by ntg_calloc(), and ntg_malloc().

void* ntg_calloc ( size_t  nmemb,
size_t  size 
)

Wrapper for glibc calloc function.

allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. Details of the allocated memory are added to the global allocation table

Parameters:
size_t nmemb The number of elements to allocate
size_t size The size in bytes of each element

References ntg_alloc(), and NTG_CALLOC.

ntg_memkeeper* ntg_find_memkeeper ( void *  ptr  ) 

Helper function to locate a pointer in the allocation table.

Returns a pointer to the searched-for pointer's memkeeper.

Parameters:
void *ptr The pointer to be searched for.

References allocation_table, DB_MEMORY, DEBUG_POST(), ntg_allocation_table_::end, ntg_memkeeper_::index, ntg_memkeeper_::mem, ntg_memkeeper_::next, and ntg_allocation_table_::start.

Referenced by ntg_kill_alias(), ntg_make_alias(), and ntg_realloc().

int ntg_free ( void *  ptr  ) 

Wrapper for glibc free function.

frees the memory space pointed to by ptr, which must have been returned by a previous call to ntg_malloc(), ntg_calloc() or ntg_realloc(). Other‐wise, or if ntg_free(ptr) has already been called before, undefine behaviour occurs. If ptr is NULL, no operation is performed. Details of the freed memory are added to the global allocation table

Parameters:
void *ptr a pointer to the memory to be freed

References allocation_table, ntg_memkeeper_::bytes, DB_MEMORY, DEBUG_POST(), ntg_allocation_table_::free_count, ntg_memkeeper_::index, ntg_memkeeper_::mem, ntg_memkeeper_::next, NTG_FAILED, NTG_MEMORY_FREE_ERROR, NTG_NO_ERROR, ntg_memkeeper_::prev, ntg_memkeeper_::reference_count, and ntg_allocation_table_::start.

Referenced by _fini(), handler_module_nodelist(), handler_send_process(), handler_send_value(), ntg_build_path_list(), ntg_connection_free(), ntg_file_find(), ntg_free_instance_counts(), ntg_get_namespace(), ntg_instance_attributes_free(), ntg_instance_free(), ntg_instance_register_namespace(), ntg_kill_alias(), ntg_path_free(), ntg_port_free(), ntg_register_namespace(), ntg_search_for_file(), ntg_server_run(), ntg_sweep_allocation_table(), ntg_value_free(), and ntg_value_set().

int ntg_kill_alias ( void *  ptr  ) 

De-reference and pointer alias.

This function will check the reference count of a pointer, and if it is 1, it will call ntg_free() on the pointer. Otherwise it will assign the pointer to NULL and decrement the reference count.

Parameters:
void *ptr The pointer to be de-referenced

References NTG_FAILED, ntg_find_memkeeper(), ntg_free(), NTG_NO_ERROR, and ntg_memkeeper_::reference_count.

void* ntg_make_alias ( void *  ptr  ) 

Return a pointer alias and increment the reference count of the pointed-to memory.

Parameters:
void *ptr The pointer to be aliased

References ntg_find_memkeeper(), and ntg_memkeeper_::reference_count.

void* ntg_malloc ( size_t  size  ) 
void* ntg_realloc ( void *  ptr,
size_t  size 
)

Wrapper for glibc realloc function.

changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes; newly allocated memory will be uninitialized. If ptr is NULL, the call is equivalent to ntg_malloc(size); if size is equal to zero, the call is equivalent to ntg_free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to ntg_malloc(), ntg_calloc() or ntg_realloc(). If the area pointed to was moved, a free(ptr) is done. The global allocation table is updated accordingly

Parameters:
void *ptr a pointer to the memory to the memory to be reallocated
size_t size The size in bytes of the new memory block

References ntg_memkeeper_::bytes, ntg_memkeeper_::mem, ntg_find_memkeeper(), and ntg_malloc().

Referenced by handler_module_register(), ntg_append_path(), ntg_append_string(), ntg_build_path_list(), ntg_file_find(), ntg_instance_register_namespace(), ntg_path_append_element(), ntg_path_to_string(), ntg_server_get_nodelist(), and ntg_value_append().

int ntg_sweep_allocation_table ( void   ) 

Generated on Tue Jan 5 14:02:29 2010 for LibIntegra by  doxygen 1.6.1