ddiakopoulos / tinyply

:earth_africa: C++11 ply 3d mesh format importer & exporter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

return unique_ptr's instead of shared_ptr's

Raikiri opened this issue · comments

Right now methods like request_properties_from_element return shared pointers to PlyData objects. However, shared pointers have their own overheads and often they have a singular owner which makes their "sharedness" redundant.

However, it's possible to assume that all requests return PlyData with a single owner by default using a unique_ptr and it's always possible to automatically convert it to a shared_ptr where shared ownership is actually needed. Due to obvious reasons, it's impossible to do the opposite and convert a pointer with shared ownership to an object with unique ownership. For example this compiles perfectly fine:

std::unique_ptr<SomeData> get_data();
int main()
{
  std::shared_ptr<SomeData> shared_data = get_data();
  std::unique_ptr<SomeData> unique_data = get_data();
  return 0;
}