Next: , Previous: , Up: Embedding API   [Contents][Index]


5.2.2 Memory management

The core library of Serveez is able to keep track of the memory an application or part of a program consumes, and also controls itself in the same manner. When you are using this memory allocator interface you can determine and afterwards remove memory leaks. This is a very important feature as servers are by nature long-lived programs.

The three allocator function pointers for malloc, realloc and free make it possible to instruct Serveez to use different kinds of memory, which might be necessary if you want the library to work with shared memory arenas or any other underlying memory API.

Function: void svz_set_mm_funcs (svz_malloc_func_t cus_malloc, svz_realloc_func_t cus_realloc, svz_free_func_t cus_free)

Set the internal memory management functions to cus_malloc, cus_realloc and cus_free, respectively. The default internal values are malloc, realloc and free.

Function: void * svz_malloc (size_t size)

Allocate size bytes of memory and return a pointer to this block.

Function: void * svz_calloc (size_t size)

Allocate size bytes of memory and return a pointer to this block. The memory is cleared (filled with zeros).

Function: void * svz_realloc (void *ptr, size_t size)

Change the size of a block of memory at ptr, previously returned by svz_malloc, to size bytes. If ptr is NULL, allocate a new block.

Function: void svz_free (void *ptr)

Free a block of memory at ptr, previously returned by svz_malloc or svz_realloc. If ptr is NULL, do nothing.

Function: char * svz_strdup (const char *src)

Duplicate the given string src if it is not NULL and has non-zero length. Return the new string.

Function: void svz_get_curalloc (size_t *to)

Write values to to[0] and to[1] representing the number of currently allocated bytes and blocks, respectively. If Serveez was not configured with ‘--enable-debug’, the values are always 0.


Next: Data structures, Previous: Library features, Up: Embedding API   [Contents][Index]