bernd
05/21/2024, 1:38 PMwithScopedMemoryAllocator
states that it frees all allocated memory after running the block. in my situation it would be beneficial to keep some intermediate-results in wasm-memory and use them in various subsequent js->wasm calls, rather than passing them out and back in.
is there a way to achieve that with kotlin (perhaupt the wasm-module can be changed to export a second memory or something like that..) ?Svyatoslav Kuzmich [JB]
05/21/2024, 1:50 PMwithScopedMemoryAllocator
, and it does release allocated memory at the end of the block.
You can reuse allocated memory if you can lift withScopedMemoryAllocator
block up the stack to include all usages within it. Not possible otherwise.Svyatoslav Kuzmich [JB]
05/21/2024, 1:53 PMbernd
05/21/2024, 2:05 PMbernd
05/21/2024, 2:06 PMSvyatoslav Kuzmich [JB]
05/21/2024, 2:12 PMfun main() {
withScopedMemoryAllocator { allocator ->
MyWholeApp.run(allocator)
}
}
Be aware that all allocations will remain active until the end of the block.bernd
05/21/2024, 2:38 PMfun precomputeAndWait() {
withScopedMemoryAllocator {
allocateMemoryAndComputeStuff()
callSomeJSFunctionThatKeepsMeWaiting()
}
}
fun usePrecomputedStuff() {
doOtherStuffWithAllocatedMemory()
}
i'm not that experienced with wasm, so i'll probably not do that for now, but might try at some point.
can you think of something to just keep a js->wasm call running for some seconds without expensive busy-waiting ?bernd
05/21/2024, 3:17 PM