Skip to main content

JS_SetMemoryLimit

Function JS_SetMemoryLimit 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn JS_SetMemoryLimit( rt: *mut JsRuntime, limit: usize, )
Expand description

JS_SetMemoryLimit: refuse an allocation that would take the heap past limit bytes.

0 means “no memory at all”, not “no limit”. The reference’s malloc_limit is a size_t initialised to -1, and js_malloc fails when malloc_size + size > limit, so a host that wants to remove a limit passes (size_t)-1. That is worth stating because it is the opposite of what a “0 disables it” instinct expects, and getting it wrong here would have made every allocation after the call fail — which is exactly what happened when this layer first mapped 0 onto “unlimited” and tests/c/embed.c caught it.

§Safety

rt must be a live runtime.