wasmerio / wasmer-java

☕ WebAssembly runtime for Java
https://medium.com/wasmer/announcing-the-first-java-library-to-run-webassembly-wasmer-jni-89e319d2ac7c
MIT License
593 stars 55 forks source link

fix: Fix the `Memory` API and add examples #35

Closed Hywan closed 4 years ago

Hywan commented 4 years ago

While adding examples/, I noticed a huge bug in the Memory API. Thus this PR contains a fix for the Memory API, and add examples.

The bug in Memory is that the inner ByteBuffer holding the memory data was invalidated as soon as the memory grown. The new API introduces the Memory.buffer() method to get a “view” (a byte buffer) of the memory data. If this object is invalidated, it's easy to get a new one. It mimics what we already do in Go, Python, PHP, Ruby etc.