Skip to content

Use make_shared to create a shared pointer#184

Closed
jbelloncastro wants to merge 1 commit intodevelopfrom
jbelloncastro-patch-1
Closed

Use make_shared to create a shared pointer#184
jbelloncastro wants to merge 1 commit intodevelopfrom
jbelloncastro-patch-1

Conversation

@jbelloncastro
Copy link

Motivation

Small code simplification.

Technical Details

Constructing a shared_ptr instance with make_shared is simpler and more efficient than using the raw pointer constructor.

Shared pointers need extra storage for the atomic reference count. make_shared has the opportunity to reserve the memory for both ref-count and the object itself in one operation, while the alternative requires two separate allocations, with the ref-count storage requiring an extra indirection to object itself.

Test Plan

The change has no effect on functionality so all the tests should have the same outcome.

Test Result

N/A

Submission Checklist

Constructing a `shared_ptr` instance with `make_shared` is simpler and more efficient than using the raw pointer constructor.

Shared pointers need extra storage for the atomic reference count. `make_shared` has the opportunity to reserve the memory for both ref-count and the object itself in one operation, while the alternative requires two separate allocations, with the ref-count storage requiring an extra indirection to object itself.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jordan-turbofish
Copy link
Collaborator

Hi @jbelloncastro. Thanks for having a look at improving hipFile. I agree that make_shared is better in general, but in this case we override new to allocate pinned host memory. make_shared will call the default allocator, which will not give us the allocation type we want.

@derobins derobins deleted the jbelloncastro-patch-1 branch February 12, 2026 23:06
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.

2 participants