JavaScript-1.5 Reference

JS_realloc Function

Summary

Reallocates a region of memory.

Syntax

void * JS_realloc(JSContext *cx, void *p, size_t nbytes);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
pvoid *Pointer to the previously allocated memory
nbytessize_tAmount of space, in bytes, to reallocate.

Description

JS_realloc reallocates a region of memory, while preserving its contents. Typically you call JS_realloc because you need to allocate more memory than orginally allocated with a call to JS_malloc, but it can also be called to decrease the amount of allocated memory, and even to deallocate the memory region entirely. p is a pointer to the previously allocated memory region, and nbytes is the size, in bytes, of the region to allocate.

Notes

Currently JS_realloc is a wrapper on the standard C realloc call. Do not make assumptions based on this underlying reliance. Future versions of JS_realloc may be implemented in a different manner.

If p is null, then JS_realloc behaves like JS_malloc. If p is not null, and nbytes is 0, JS_realloc returns null and the region is deallocated. As with JS_malloc, new space is not initialized and should be regarded to contain meaningless information.

If a reallocation request fails, JS_realloc passes cx to JS_ReportOutOfMemory to report the error.

Whenever the pointer returned by JS_realloc differs from p, the old region of memory is deallocated and should not be used.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_ReportOutOfMemory | JS_free | JS_malloc ]

This page was generated by APIDOC