diff options
| author | Jon Ashburn <jon@lunarg.com> | 2015-08-27 15:23:52 -0600 |
|---|---|---|
| committer | Jon Ashburn <jon@lunarg.com> | 2015-09-04 15:46:31 -0600 |
| commit | 65a2bcfa67d4ce71f0da622b67a12af80e47914f (patch) | |
| tree | a35f3900ffdeac67bde1f169f059eb901da83cca /loader | |
| parent | dc474d1852efb52a666053ab6021ef71fbecda90 (diff) | |
| download | usermoji-65a2bcfa67d4ce71f0da622b67a12af80e47914f.tar.xz | |
loader: Add support for realloc using the app allocation callbacks.
Diffstat (limited to 'loader')
| -rw-r--r-- | loader/loader.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/loader/loader.c b/loader/loader.c index 11eda894..e429b0f7 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -146,6 +146,33 @@ void loader_heap_free( free(pMem); } +void* loader_heap_realloc( + struct loader_instance *instance, + void *pMem, + size_t orig_size, + size_t size, + VkSystemAllocType alloc_type) +{ + if (pMem == NULL || orig_size == 0) + return loader_heap_alloc(instance, size, alloc_type); + if (size == 0) { + loader_heap_free(instance, pMem); + return NULL; + } + if (instance && instance->alloc_callbacks.pfnAlloc) { + if (size <= orig_size) { + memset(((uint8_t *)pMem) + size, 0, orig_size - size); + return pMem; + } + void *new_ptr = instance->alloc_callbacks.pfnAlloc(instance->alloc_callbacks.pUserData, size, 4, alloc_type); + if (!new_ptr) + return NULL; + memcpy(new_ptr, pMem, orig_size); + instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMem); + } + return realloc(pMem, size); +} + static void loader_log(VkFlags msg_type, int32_t msg_code, const char *format, ...) { |
