EtherLib/dynmem.h

51 lines
1.2 KiB
C

#ifndef CORE_ETHERLIB_DYNMEM
#define CORE_ETHERLIB_DYNMEM
#include <stdint.h>
#ifdef DYNMEM_DEBUG
#include <stdio.h>
#endif
#ifdef VALGRIND_DEBUG
#include <stdlib.h>
#include <stdio.h>
#endif
/**
* Initialize EtherLib dynamic memory management subsystem,
* based on heap pointer and size given in etherlib_options.h
*/
void dynmem_init();
/**
* Dynamically allocate memory from EtherLib's pool.
* @param size requested size
* @return pointer to allocated area or NULL on failure
*/
void * dynmem_alloc_(uint32_t size);
#ifdef DYNMEM_DEBUG
#define dynmem_alloc(size) dynmem_alloc_(size); MSG("ALLOC: %d %s() in %s:%d\n", size, __FUNCTION__, __FILE__, __LINE__)
#elif defined(VALGRIND_DEBUG)
#define dynmem_alloc(size) malloc(size)
#else
#define dynmem_alloc(size) dynmem_alloc_(size)
#endif
/**
* Release allocated block.
* @param ptr pointer to allocated area
*/
void dynmem_free_(const void * ptr);
#ifdef DYNMEM_DEBUG
#define dynmem_free(ptr) MSG("FREE: %s() in %s:%d\n", __FUNCTION__, __FILE__, __LINE__), dynmem_free_(ptr)
#elif defined(VALGRIND_DEBUG)
#define dynmem_free(p) free(p)
#else
#define dynmem_free(ptr) dynmem_free_(ptr)
#endif /* CORE_ETHERLIB_DYNMEM */
#endif //ETHERLIB_DYNMEM_H