Created
February 26, 2017 10:24
-
-
Save adishavit/7cd50b3c202c9e8b4ad9518b208727d8 to your computer and use it in GitHub Desktop.
Copy JS Int32Array to Emscripten heap for passing as C array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _arrayToHeap(typedArray){ | |
var numBytes = typedArray.length * typedArray.BYTES_PER_ELEMENT; | |
var ptr = Module._malloc(numBytes); | |
var ptr_i32 = ptr >> 2; // divide byte offset by 4 to account for 4-byte int pointer | |
var heapBytes = Module.HEAP32.subarray(ptr_i32, ptr_i32 + typedArray.length); | |
heapBytes.set(typedArray); | |
return heapBytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment