Skip to content

_malloc/stackAlloc #21468

Closed Answered by kripken
cemalgnlts asked this question in Q&A
Mar 4, 2024 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Technically you can also free the pointer from stackAlloc (using stackRestore). However, the ABI used by clang and Emscripten for the wasm stack ensures that the stack is cleaned up when the parent unwinds anyhow.

Concretely, imagine we enter a function. It stores the current stack pointer as temp. We can then do various small allocations in that function, and do not need to free anything there, because when the function exits it will do stackRestore(temp), which in effect frees all allocations in the middle.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@cemalgnlts
Comment options

@kripken
Comment options

@cemalgnlts
Comment options

@sbc100
Comment options

@cemalgnlts
Comment options

Answer selected by cemalgnlts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants