Add realloc func argument for memory allocator (#191)

This commit is contained in:
wenyongh
2020-03-08 21:18:18 +08:00
committed by GitHub
parent 057c849fc0
commit 180ee4c78a
12 changed files with 213 additions and 42 deletions

View File

@ -58,6 +58,16 @@ unsigned bh_memory_pool_size();
*/
void* bh_malloc(unsigned int size);
/**
* This function reallocates a memory chunk from system
*
* @param ptr the original memory
* @param size bytes need allocate
*
* @return the pointer to memory allocated
*/
void* bh_realloc(void *ptr, unsigned int size);
/**
* This function frees memory chunk
*
@ -68,9 +78,11 @@ void bh_free(void *ptr);
#else
void* bh_malloc_profile(const char *file, int line, const char *func, unsigned int size);
void* bh_realloc_profile(const char *file, int line, const char *func, void *ptr, unsigned int size);
void bh_free_profile(const char *file, int line, const char *func, void *ptr);
#define bh_malloc(size) bh_malloc_profile(__FILE__, __LINE__, __func__, size)
#define bh_realloc(ptr, size) bh_malloc_profile(__FILE__, __LINE__, __func__, ptr, size)
#define bh_free(ptr) bh_free_profile(__FILE__, __LINE__, __func__, ptr)
/**

View File

@ -23,6 +23,9 @@ mem_allocator_destroy(mem_allocator_t allocator);
void *
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size);
void *
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
void
mem_allocator_free(mem_allocator_t allocator, void *ptr);