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

Leverage std::make_unique & std::make_shared to create objects in the heap #3254

Open
wants to merge 1 commit into
base: v3/master
Choose a base branch
from

Conversation

eduar-hte
Copy link
Contributor

what

Replace naked new calls to create object instances in the heap that are then used to create std::unique_ptr & std::shared_ptr instances.

why

Simplifies code and follows C++ Core Guidelines, see R.22: Use make_shared() to make shared_ptrs & R.23: Use make_unique() to make unique_ptrs

Additionally, the use of std::make_shared allows for an optimization by which the shared pointer's control block and the object can be allocated in the same memory block, which increasees memory locality (and thus performance).

- Simpler code & more efficient because control block can be allocated
  with object.
Copy link

sonarcloud bot commented Sep 10, 2024

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

Successfully merging this pull request may close these issues.

1 participant