SPRAAK
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Functions
dynmem.c File Reference

Dynamic memory management & checking. More...

Data Structures

struct  SprMPool
 

Macros

#define SPR_MPOOL_CHUNK_SZ
 
#define SPR_MPOOL_INITIALIZER(type, next_el)
 
#define SPR_MPOOL_INIT(mpool, type, next_el)
 

Functions

void * spr_free (void *ptr, const SprMsgId *routine, const char *item)
 
void * spr_malloc (size_t size, const SprMsgId *routine, const char *item)
 
void * spr_realloc (void *ptr, size_t size, const SprMsgId *routine, const char *item)
 
size_t spr_dynmem_item_cnt (void)
 
size_t spr_dynmem_byte_cnt (void)
 
unsigned int spr_dynmem_check (SprMsgId *routine, const char *id)
 Check if the heap is corrupted. This routine is not mult-threading safe. More...
 
void spr_hexdump2buf (char *dst, const void *data, size_t size)
 
int spr_dynmem_dump (SprStream *fd)
 Dump the data that is still allocated to file fd. This routine is not mult-threading safe. More...
 
char * spr_strdup (const char *src, const SprMsgId *routine, const char *item)
 
char * spr_strndup (const char *src, size_t size, const SprMsgId *routine, const char *item)
 
char * spr_strcpy (char **restrict dst, const char *restrict src)
 
char * spr_strcat (char *restrict str1, const char *restrict str2, int *restrict str1_len, int str2_len, int *restrict alen)
 
char * spr_dynstr2alloc (SprDynStr str)
 
SprDynStr spr_dynstr_free (SprDynStr str, const SprMsgId *routine, const char *item)
 
SprDynStr spr_dynstr_alloc (size_t size, const SprMsgId *routine, const char *item)
 
SprDynStr spr_dynstr_realloc (SprDynStr str, size_t size, const SprMsgId *routine, const char *item)
 
SprDynStr spr_dynstr_enlarge (SprDynStr str, size_t size, const SprMsgId *routine, const char *item)
 
size_t spr_dynstr_maxlen (SprDynStr str)
 
SprDynStr spr_dynstr_cpy (SprDynStr dst, const char *src)
 
SprDynStr spr_dynstr_ncpy (SprDynStr dst, const char *src, size_t src_len)
 
SprDynStr spr_dynstr_dup (const char *src, const SprMsgId *routine, const char *item)
 
SprDynStr spr_dynstr_ndup (const char *src, size_t src_len)
 
SprDynStr spr_dynstr_cat (SprDynStr restrict str1, const char *restrict str2, int *restrict str1_len, int str2_len)
 
const char * spr_str_nonull_ (const char *str)
 
const char * spr_str_nonull (const char *str, const char *str_null)
 
const char * spr_str_no_empty (const char *str, const char *str_empty)
 
size_t spr_dynmem_pool_count_alloc (const SprMPool *mpool)
 
size_t spr_dynmem_pool_count_free (const SprMPool *mpool)
 
size_t spr_dynmem_pool_free (SprMPool *mpool, SprMsgId *routine)
 
void * spr_dynmem_pool_enlarge (SprMPool *mpool)
 
void spr_dynmem_cfg (int mode)
 

Detailed Description

Dynamic memory management & checking.

This module provides routines for dynamic memory management (allocation and release) with error reporting and configurable checks for memory leaks.

The routines fall in three groups:

The system also allows turning on additional accounting and checking. This should allow easy and fast detection of memory leaks, double free's, and simple buffer overrun errors. The additional accounting and checking can be enabled by either using the '–check_dynmem <lvl>' option when calling a program or by setting the 'SPR_DYNMEM_CHECK' environment variable. See spr_dynmem_cfg() for the different modes one can select.

Note
These memory management functions are coded using the standard C functions 'malloc', 'free' and 'realloc'. Only the functions present in this file are to be used in the SPRAAK package. Memory allocated by system calls is kept out of the accounting system and will not be reported.
Author
Kris Demuynck
Date
13/09/2007
Revision History:
24/08/1994 - FS
Original framework and first implementation by Frank Schoeters (ESAT)
15/05/1996 - KD
New code having far more checks programmed by Kris Demuynck (ESAT)
02/10/1998 - KD
Allocation of small blocks (extracted from cwr_search.c) (ESAT)
13/09/2007 - KD
New code (MT-safe checks) + dynamic strings (SPRAAK)
Environment variables:
SPR_DYNMEM_CHECK
set the level of accounting and checking, See spr_dynmem_cfg() for more details.
Bug:
The spr_dynmem_cfg() routine should never be called (is called automatically from the spraak_ini() or spraak_ini_prog() routine).