In C++, one can return temporary std::vector's like this:
std::vector<int> test() {
std::vector<int> output = { 1, 2, 3 };
return output;
}
and not have to worry about temporary vector being destructed afterwards, thanks to RVO or move semantics.
If I were to return emscripten::val in a similar manner, and coerce it into a TypedArray:
emscripten::val test() {
std::vector<int> output = { 1, 2, 3 };
return emscripten::val(typded_memory_view(output.size(), output.data()));
}
Can I still rest assured that the TypedArray I receive on JS won't be corrupted once the temp vector is destroyed?
Is this handled in a similar manner (i.e. using RVO or move semantics) with emscripten::val?