The memory allocation macros assume C's 'malloc', 'realloc' and 'free' by default. However, the user may override these by calling oski_SetMalloc(), oski_SetRealloc(), and oski_SetFree(), respectively.
Go to the source code of this file.
Defines | |
#define | INC_OSKI_MALLOC_H |
oski/malloc.h has been included. | |
#define | oski_Malloc(elem_type, num_elems) |
Customized macro for memory allocation. | |
#define | oski_MallocNoError(elem_type, num_elems) |
Customized macro for memory allocation with no error reporting. | |
#define | oski_Realloc(ptr_addr, elem_type, num_elems) |
Customized macro for memory re-allocation. | |
#define | oski_Free(ptr) oski_FreeInternal( ptr ) |
Customized macro for memory release. | |
Typedefs | |
typedef void *(* | oski_mallocfunc_t )(size_t) |
Type specifying a 'malloc'-compatible function. | |
typedef void *(* | oski_reallocfunc_t )(void *, size_t) |
Type specifying a 'realloc'-compatible function. | |
typedef void(* | oski_freefunc_t )(void *) |
Type specifying a 'free'-compatible function. | |
Functions | |
void * | oski_MallocInternal (const char *elem_type, size_t elem_size, size_t num_elems, const char *source_file, unsigned long line_number) |
Allocate a block of memory, and call the error handler on error. | |
int | oski_ReallocInternal (void **p_ptr, const char *elem_type, size_t elem_size, size_t num_elems, const char *source_file, unsigned long line_number) |
Reallocate a block of memory, and call the error handler on error. | |
void | oski_FreeInternal (void *ptr) |
Free a previously allocated block of memory. | |
int | oski_MultiMalloc (const char *file, unsigned long line, int k,...) |
Performs multiple memory allocations. | |
void | oski_FreeAll (int k,...) |
Free a list of pointers. | |
oski_mallocfunc_t | oski_GetMalloc (void) |
Returns the current memory allocation function. | |
oski_reallocfunc_t | oski_GetRealloc (void) |
Returns the current memory reallocation routine. | |
oski_freefunc_t | oski_GetFree (void) |
Returns the function used to free allocated memory. | |
oski_mallocfunc_t | oski_SetMalloc (oski_mallocfunc_t new_func) |
Change the current memory allocation function. | |
oski_reallocfunc_t | oski_SetRealloc (oski_reallocfunc_t new_func) |
Change the current memory re-allocation function. | |
oski_freefunc_t | oski_SetFree (oski_freefunc_t new_func) |
Change the function used to free allocated memory. | |
void | oski_ZeroMem (void *buf, size_t num_bytes) |
Zero out bytes in a buffer. |
|
Customized macro for memory release.
|
|
Value: (elem_type *)oski_MallocInternal( \ #elem_type, sizeof(elem_type), (num_elems), __FILE__, __LINE__ )
On error, this macro executes the default global error handler with information about the allocation error.
|
|
Value: (elem_type *)oski_MallocInternal( \ #elem_type, sizeof(elem_type), (num_elems), NULL, -1 ) This macro is identical to oski_Malloc() except that it does not call the error handler on error. |
|
Value: oski_ReallocInternal( ptr_addr, #elem_type, sizeof(elem_type), \ num_elems, __FILE__, __LINE__ )
On error, this routine returns an error code (integer less than 0) and calls the current error handler. |
|
Free a previously allocated block of memory.
This routine is for the library's internal use only and should not normally be called directly by users of the library.
|
|
Allocate a block of memory, and call the error handler on error.
If source_file == NULL, then this routine does not call the error handler on failure. |
|
Performs multiple memory allocations. Returns a 0 and pointers to all allocated buffers on success. Otherwise, returns an error code and allocates no buffers. For example, the call: size_t m_bytes = sizeof(double) * m; double* pm; size_t n_bytes = sizeof(char) * n; char* pn; size_t k_bytes = sizeof(struct my_object) * k; struct my_object* pk; int err = oski_MultiMalloc( file, line, 3, m_bytes, &pm, n_bytes, &pn, k_bytes, &pk ); |
|
Reallocate a block of memory, and call the error handler on error.
|
|
Change the function used to free allocated memory.
|
|
Change the current memory allocation function.
|
|
Change the current memory re-allocation function.
|
|
Zero out bytes in a buffer.
|