1

I have a c++ function that accepts 2 arrays and multiplies them together.

void multData(unsigned char *arr1, unsigned char *arr2) {
   for(i=0;i<10;i++){
    arr1[i] = arr1[i] * arr2[i];
   }
}

When I compile it I allocate space for both arrays in the heap using malloc.

var mallocBuff = Module._malloc(arr1.length); 
var mallocBuff2 = Module._malloc(arr2.length); 

Then after filling the newly malloced data with values I'll call it like this:

Module.ccall('multData', null, ['number'], [mallocBuff], [mallocBuff2]);

However after some testing I realize that only the first array is receiving the malloc pointer. The second array is just a bunch of 0's.

Is there anyway to pass 2 arrays into a wasm compiled function?

1 Answer 1

1

The ccall signature is ccall(ident, returnType, argTypes, args, opts). API Reference

Module.ccall('multData', null, ['number', 'number'], [mallocBuff, mallocBuff2]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.