On Mon, Aug 7, 2023 at 7:52 AM 'Michael Hagar' via emscripten-discuss < emscripten-discuss@googlegroups.com> wrote:
> It's mentioned in the docs here: > https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html?highlight=memory_growth#access-memory-from-javascript > > That if using the ALLOW_MEMORY_GROWTH option, the JS side needs to refresh > the views on the memory buffer. > > If I used Module._malloc, and then memory grows, are the values returned > from the original Module._malloc call still valid? If the values returned > refer to specific positions in the underlying buffer, it seems like they > would be invalidated, but that doesn't seem to be the case (they still seem > valid). > > What's going on here? I have a feeling I'm misunderstanding how Emscripten > works with C++ memory. Pointers as returned from _malloc are relative to the beginning of the module's linear memory (ie, with the start at 0 for code inside Wasm or JS viewing through a typed array). If the WebAssembly runtime needs to move the underlying buffer in the process address space (which can happen on a 32-bit system if not enough address space was initially reserved), this will be entirely transparent to WASM and JavaScript code in terms of pointers; the new buffer will contain the same data at the same locations, but be larger. My understanding is that if you are passing around Typed Array views into the linear memory on the JS side, that those might become stale? Though I'm not 100% sure if that's current since Wasm came in and added its own method of underlying buffer growth. :D -- brion > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to emscripten-discuss+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/432220a3-fcc4-46db-901e-145deb1fcdd5n%40googlegroups.com > <https://groups.google.com/d/msgid/emscripten-discuss/432220a3-fcc4-46db-901e-145deb1fcdd5n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAFnWYTmgh1bHTJkrphtB-kfknZWiR48hE_%2B8RDnC3Scxb6ve_g%40mail.gmail.com.