Next: 4.10.6 mq
Up: 4.10 Classes
Previous: 4.10.4 mb
  Contents
  Index
Subsections
4.10.5 mem
The mem class implements a memory allocation (malloc) wrapper. For
the debug version of libonyx, extra information is hashed for each
memory allocation that allows tracking of the following:
- File/line number of allocation.
- Double allocation/deallocation of the same address.
- Memory leaks (memory left allocated at mem destruction time).
If any memory leaks are detected, diagnostic output is printed to
stderr.
Also, the debug version of libonyx sets all newly allocated bytes to
0xa5, and all deallocated bytes to 0x5a (except in the case of
mem_calloc()). This tends to cause things to break sooner when
uninitialized or deallocated memory is referenced.
In general, the mem class doesn't need to be used directly.
Instead, there are several preprocessor macros that can be used:
cw_malloc(), cw_calloc(),
cw_realloc(), and cw_free().
cw_mem_t * mem_new(cw_mem_t *a_mem, cw_mem_t
*a_internal):
- Input(s):
-
- a_mem:
- Pointer to space for a mem, or NULL.
- a_internal:
- Pointer to a mem to use for internal
memory allocation, or NULL.
- Output(s):
-
- retval:
- Pointer to a mem.
- Exception(s):
-
- CW_ONYXX_OOM.
-
- Description:
- Constructor.
void mem_delete(cw_mem_t *a_mem):
- Input(s):
-
- a_mem:
- Pointer to a mem.
- Output(s):
- None.
- Exception(s):
- None.
- Description:
- Destructor.
void * mem_malloc_e(cw_mem_t *a_mem, size_t a_size, const
char *a_filename, cw_uint32_t a_line_num):
void * mem_malloc(cw_mem_t *a_mem, size_t a_size):
void * cw_malloc(size_t a_size):
- Input(s):
-
- a_mem:
- Pointer to a mem.
- a_size:
- Size of memory range to allocate.
- a_filename:
- Should be __FILE__.
- a_line_num:
- Should be __LINE__.
- Output(s):
-
- retval:
- Pointer to a memory range.
- Exception(s):
-
- CW_ONYXX_OOM.
-
- Description:
- malloc() wrapper.
void * mem_calloc_e(cw_mem_t *a_mem, size_t a_number,
size_t a_size, const char *a_filename, cw_uint32_t a_line_num):
void * mem_calloc(cw_mem_t *a_mem, size_t a_number,
size_t a_size):
void * cw_calloc(size_t a_number, size_t a_size):
- Input(s):
-
- a_mem:
- Pointer to a mem.
- a_number:
- Number of elements to allocate.
- a_size:
- Size of each element to allocate.
- a_filename:
- Should be __FILE__.
- a_line_num:
- Should be __LINE__.
- Output(s):
-
- retval:
- Pointer to a zeroed memory range.
- Exception(s):
-
- CW_ONYXX_OOM.
-
- Description:
- calloc() wrapper.
void * mem_realloc_e(cw_mem_t *a_mem, void *a_ptr, size_t
a_size, size_t a_old_size, const char *a_filename, cw_uint32_t
a_line_num):
void * mem_realloc(cw_mem_t *a_mem, void *a_ptr, size_t
a_size):
void * cw_realloc(void *a_ptr, size_t a_size):
- Input(s):
-
- a_mem:
- Pointer to a mem.
- a_ptr:
- Pointer to memory range to be reallocated.
- a_size:
- Size of memory range to allocate.
- a_old_size:
- Size of memory range previously pointed to by
a_ptr.
- a_filename:
- Should be __FILE__.
- a_line_num:
- Should be __LINE__.
- Output(s):
-
- retval:
- Pointer to a memory range.
- Exception(s):
-
- CW_ONYXX_OOM.
-
- Description:
- realloc() wrapper.
void mem_free_e(cw_mem_t *a_mem, void *a_ptr, size_t
a_size, const char *a_filename, cw_uint32_t a_line_num):
void mem_free(cw_mem_t *a_mem, void *a_ptr, size_t
a_size):
void cw_free(void *a_ptr):
- Input(s):
-
- a_mem:
- Pointer to a mem.
- a_ptr:
- Pointer to to memory range to be freed.
- a_size:
- Sizef of memory range pointed to by a_ptr.
- a_filename:
- Should be __FILE__.
- a_line_num:
- Should be __LINE__.
- Output(s):
- None.
- Exception(s):
- None.
- Description:
- free() wrapper.
Next: 4.10.6 mq
Up: 4.10 Classes
Previous: 4.10.4 mb
  Contents
  Index
Jason Evans
2003-01-31