name: duk_realloc_raw proto: | void *duk_realloc_raw(duk_context *ctx, void *ptr, duk_size_t size); summary: |

Resize a previous allocation made with the allocation functions registered to the context. The ptr argument points to the previous allocation while size is the new allocation size. The call returns a pointer to the new allocation which may have a different pointer than the previous one. If the reallocation fails, a NULL is returned and the previous allocation is still valid. Reallocation failure should only be possible when the new size is larger than the previous size (i.e. caller tries to grow the allocation). The attempt to reallocate cannot trigger a garbage collection, and the allocated memory is not automatically garbage collected. If allocated size is extended from previous allocation, the newly allocated bytes are not automatically zeroed and may contain arbitrary garbage.

The exact behavior depends on the ptr and size arguments as follows:

Memory reallocated with duk_realloc_raw() can be freed with either duk_free() or duk_free_raw().

example: | void *buf = duk_alloc_raw(ctx, 1024); if (buf) { void *buf2 = duk_realloc_raw(ctx, 2048); if (!buf2) { printf("failed to reallocate, 'buf' still valid\n"); } else { printf("reallocate successful, 'buf2' now valid\n"); } } tags: - memory seealso: - duk_realloc introduced: 1.0.0