dcodeIO / webassembly

A minimal toolkit and runtime to produce and run WebAssembly modules.
Other
816 stars 31 forks source link

malloc vs memory.grow #19

Closed gillesboisson closed 6 years ago

gillesboisson commented 6 years ago

Hi, Awesome minimalist tool, all is working fine expect when I try to grow memory or use malloc.

Do I have to grow memory at a specific time ?

I'm not a C expert maybe i'm doing something wrong. I working on mac and using npm lib using webpack to compile the final app.

Otherwise all's fine I did some test on matrix operation using a custom C port of gl-matrix I have a x10 execution speed with optimisation enabled. Performance is much less significant when I use math function (sin,cos) on matrix rotation), I have x1.3 exec speed.

Cheers,

dcodeIO commented 6 years ago

When growing the memory, the memory object on the JS side changes. It basically throws away the old buffer and makes a new, larger one with the same contents. Then, when accessing the old one, there's the error you are seeing.

There is this little function in the loader that should take care of it, but it must be called every time memory grows, for example by importing void _grow() and calling it.

gillesboisson commented 6 years ago

Thanks it works perfectly,