Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing arrays #3

Open
neurolabusc opened this issue Dec 6, 2021 · 0 comments
Open

Passing arrays #3

neurolabusc opened this issue Dec 6, 2021 · 0 comments

Comments

@neurolabusc
Copy link

Hello,
The included test.js demonstrates that malloc is able to allocate and release memory, but it does not make it explicit how arrays of data can be passed between C and JavaScript. I realize that I am unfamiliar with WASM and JavaScript. However, I think many developers would benefit by having a simple demo showing how to use walloc for computation.

I have provided a simple demo here. The JavaScript writes to an array, and the C code returns the sum as well as modifying the array. This seems to do what I want. However, while it works, I am not freeing the array. It would be great if you could provide a minimal demo that illustrates best practices for walloc.

Here is my demo running:

walloc > emcc -O2 -s ALLOW_MEMORY_GROWTH -s MAXIMUM_MEMORY=4GB -s WASM=1 -I. func.c walloc.c -o funcx.js; node test.js

Instance [WebAssembly.Instance] {}
input  Uint8ClampedArray(8) [
  0, 1, 0, 1,
  0, 1, 0, 1
] ...
Sum: 3554568
result  Uint8ClampedArray(8) [
  0, 1, 2, 3,
  4, 0, 1, 2
] ...
Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant