-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
I'm trying to find a way to efficiently convert TypedArrays into std::vector (and vice versa) using Embind. I'm currently using vecFromJSArray
but that's inefficient when compared to passing a pointer and directly accessing Emscripten heap as described here. However, playing with the heap is a bit cumbersome on the JS side, so I wonder if there is a better way to convert typed arrays. Maybe we can get a pointer to the begging of the TypedArray's buffer and use the length to find the rest and build a vector, something like this:
using namespace emscripten;
std::vector<double> vecFromJSTypedArray(const val& a) {
return std::vector<double>(a["buffer"].as<?>(), a["buffer"].as<?>() + a["length"].as<unsigned>());
}
Not sure how to do it though, I'd appreciate any pointers (no pun intended) here.
Sciss