Add facilities for shared/weak ownership #264
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New Features
allocate_proxy_shared()make_proxy_shared()weak_facadeweak_proxybasic_facade_builder::support_weak_ownership(compatible withstd::weak_ptr)Comparing to
std::shared_ptrstd::shared_ptrimplements type erasure on the deleter with a cost. It is not needed forproxy.std::shared_ptrimplements conversion tostd::weak_ptrwith a cost.proxycan opt-out if weak ownership is not desired. From GitHub search result,std::shared_ptrhas 3.9M occurrences, whilestd::weak_ptronly has 156k occurrences (4%).allocate_proxy_shared()andmake_proxy_shared()can optimize the implementation at compile-time based on whethersupport_weak_ownershipis specified by a facade type.std::shared_ptrsupports creation from a raw pointer, leading to limitations in implementing a space-efficient memory layout.std::shared_ptrmaintains the object and the control block in two parts. Althoughstd::make_sharedcan avoid another allocation, it at least allocates a space to store the address of the object, which can be eliminated (similar toboost::intrusive_ptr).Testing