diff options
| author | Bernard Xiong <[email protected]> | 2013-04-17 22:09:48 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2013-04-17 22:09:48 +0800 |
| commit | 608bf2cb3deda4b682aa1a9a9f2a71a4c0416a48 (patch) | |
| tree | b48da330f5ba978a467758ef306dda0e21154fba /src/memheap.c | |
| parent | 8185f9888d7a6fac14cd74681d2f864fc837c39e (diff) | |
add rt_memheap_realloc function
Diffstat (limited to 'src/memheap.c')
| -rw-r--r-- | src/memheap.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/memheap.c b/src/memheap.c index 941c73b9e2..59a499e8db 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -13,6 +13,7 @@ * 2012-10-16 Bernard add the mutex lock for heap object. * 2012-12-29 Bernard memheap can be used as system heap. * change mutex lock to semaphore lock. + * 2013-04-10 Bernard add rt_memheap_realloc function. */ #include <rthw.h> @@ -277,6 +278,27 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size) } RTM_EXPORT(rt_memheap_alloc); +void *rt_memheap_realloc(struct rt_memheap* heap, void* ptr, rt_size_t newsize) +{ + void* new_ptr; + if (newsize == 0) + { + rt_memheap_free(ptr); + } + + if (ptr == RT_NULL) + { + return rt_memheap_alloc(heap, newsize); + } + + new_ptr = rt_memheap_alloc(heap, newsize); + if (new_ptr == RT_NULL) return RT_NULL; + + rt_memcpy(new_ptr, ptr, newsize); + return new_ptr; +} +RTM_EXPORT(rt_memheap_realloc); + void rt_memheap_free(void *ptr) { rt_err_t result; |
