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

@ -26,6 +26,12 @@ mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
return gc_alloc_vo_h((gc_handle_t) allocator, size);
}
void *
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size)
{
return gc_realloc_vo_h((gc_handle_t) allocator, ptr, size);
}
void mem_allocator_free(mem_allocator_t allocator, void *ptr)
{
if (ptr)
@ -101,8 +107,8 @@ mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
if (size == 0)
/* tlsf doesn't allow to allocate 0 byte */
size = 1;
/* tlsf doesn't allow to allocate 0 byte */
size = 1;
vm_mutex_lock(&allocator_tlsf->lock);
ret = tlsf_malloc(allocator_tlsf->tlsf, size);
@ -110,6 +116,22 @@ mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
return ret;
}
void *
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size)
{
void *ret;
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
if (size == 0)
/* tlsf doesn't allow to allocate 0 byte */
size = 1;
vm_mutex_lock(&allocator_tlsf->lock);
ret = tlsf_realloc(allocator_tlsf->tlsf, ptr, size);
vm_mutex_unlock(&allocator_tlsf->lock);
return ret;
}
void
mem_allocator_free(mem_allocator_t allocator, void *ptr)
{