Go to the first, previous, next, last section, table of contents.


Memory API

You can override the default memory management routines by defining replacements and including them in the link command prior to libkarel. If you do decide to override the memory management routines, they must all be redefined. It is not possible to redefine some memory management routines and not others.

The default implementation uses the standard C library calls calloc, malloc, free, and realloc.

Memory Management: void * ktr_calloc (size_t nmemb, size_t size)
Allocates an array of nmemb elements, each of size bytes. Returns a pointer to the allocated memory, or NULL if the allocation failed.

Memory Management: void * ktr_malloc (size_t size)
Allocates size bytes. Returns a pointer to the allocated memory, or NULL if the allocaiton failed.

Memory Management: void ktr_free (void *ptr);
Frees memory previously allocated by ktr_calloc, ktr_malloc, or ktr_realloc.

Memory Management: void * ktr_realloc (void *ptr, size_t size);
Attempts to resize the memory block pointed to by ptr. If ptr is NULL, the call is equivalent to malloc(size). If size is equal to zero, the call is equivalent to free(ptr). Unless ptr is NULL, it must have been allocated by a previous call to ktr_calloc or ktr_malloc. Returns a pointer to the new block of memory. If the allocation fails, NULL is returned and the original block of memory is untouched.


Go to the first, previous, next, last section, table of contents.