mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1017 B
34 lines
1017 B
name: duk_realloc
|
|
|
|
proto: |
|
|
void *duk_realloc(duk_context *ctx, void *ptr, duk_size_t size);
|
|
|
|
summary: |
|
|
<p>Like <code><a href="#duk_realloc_raw">duk_realloc_raw()</a></code> but may
|
|
trigger a garbage collection to satisfy the request. However, the
|
|
allocated memory itself 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.</p>
|
|
|
|
<p>Memory reallocated with <code>duk_realloc()</code> can be freed with either
|
|
<code><a href="#duk_free">duk_free()</a></code> or
|
|
<code><a href="#duk_free_raw">duk_free_raw()</a></code>.</p>
|
|
|
|
example: |
|
|
void *buf = duk_alloc(ctx, 1024);
|
|
if (buf) {
|
|
void *buf2 = duk_realloc(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_raw
|
|
|
|
introduced: 1.0.0
|
|
|