Skip to content

Question about life cycle of emscripten::val returned from temporary vector #16641

@waterrhett

Description

@waterrhett

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions