WasmPStack
The "pstack" (pseudo-stack) API is a special-purpose allocator intended solely for use with allocating small amounts of memory such as that needed for output pointers. It is more efficient than the scoped allocation API, and covers many of the use cases for that API, but it has a tiny static memory limit (with an unspecified total size no less than 2kb).
The pstack API is typically used like:
const pstack = sqlite3.wasm.pstack;
const stackPtr = pstack.pointer;
try {
const ptr = pstack.alloc(8);
// ==> pstack.pointer === ptr
const otherPtr = pstack.alloc(8);
// ==> pstack.pointer === otherPtr
...
}finally{
pstack.restore(stackPtr);
// ==> pstack.pointer === stackPtr
}Functions
Attempts to allocate the given number of bytes from the pstack. On success, it zeroes out a block of memory of the given size, adjusts the pstack pointer, and returns a pointer to the memory. On error, returns throws a WasmAllocError. The memory must eventually be released using pstack.restore().
Attempts to allocate the given number of bytes from the pstack.
alloc()'s n chunks, each sz bytes, as a single memory block and returns the addresses as an array of n element, each holding the address of one chunk.
alloc()'s n chunks, each sz bytes, as a single memory block and returns the addresses as an array of n element, each holding the address of one chunk.
Allocates a pointer and set is to 0.
Allocates howMany pointers as a single chunk of memory and zeroes them out.