Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return unique_ptr's instead of shared_ptr's #42

Open
Raikiri opened this issue Jun 13, 2020 · 0 comments
Open

return unique_ptr's instead of shared_ptr's #42

Raikiri opened this issue Jun 13, 2020 · 0 comments

Comments

@Raikiri
Copy link

Raikiri commented Jun 13, 2020

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant