2009-02-04 14:00:44 +03:00
|
|
|
#ifndef MHL_MEMORY_H
|
|
|
|
#define MHL_MEMORY_H
|
2009-01-09 21:49:34 +03:00
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-01-15 16:10:45 +03:00
|
|
|
/* allocate a chunk of stack memory, uninitialized */
|
|
|
|
#define mhl_mem_alloc_u(sz) (malloc(sz))
|
2009-01-13 17:24:41 +03:00
|
|
|
|
2009-01-15 16:10:45 +03:00
|
|
|
/* allocate a chunk of stack memory, zeroed */
|
|
|
|
#define mhl_mem_alloc_z(sz) (calloc(1,sz))
|
2009-01-09 21:49:34 +03:00
|
|
|
|
|
|
|
/* free a chunk of memory from stack, passing NULL does no harm */
|
|
|
|
static inline void mhl_mem_free(void* ptr)
|
|
|
|
{
|
2009-01-15 16:10:45 +03:00
|
|
|
if (ptr) free(ptr);
|
2009-01-09 21:49:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free an ptr and NULL it */
|
2009-02-04 14:00:44 +03:00
|
|
|
#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0)
|
2009-01-09 21:49:34 +03:00
|
|
|
|
2009-01-15 16:10:45 +03:00
|
|
|
/* allocate a chunk on stack - automatically free'd on function exit */
|
|
|
|
#define mhl_stack_alloc(sz) (alloca(sz))
|
|
|
|
|
|
|
|
/* re-alloc memory chunk */
|
|
|
|
#define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz))
|
|
|
|
|
|
|
|
#endif
|