Std :: allocate_shared, allow reference counting of a shared pointer from a custom allocator and in a separate distribution

Doing sharing improves performance by using a single distribution for reference and object counting, is it possible to use a custom allocator along with std :: allocate_shared and still have one distribution, according to the test code I wrote that this does not happen:   sample

I know that boost :: intrusive, but it has extra code to write and that may go wrong.

+4
source share
1 answer

using some debugging, it turned out that std :: allocate_shared does what is expected, it allows you to make only one distribution for both your object and the reference counter.

The code is adjusted below: select the shared file

Here, the new operator is called exactly once for std :: make_shared and std :: allocate_shared. Using this pool of objects can be created, and you can have the same efficiency expected from boost :: intrusive_ptr, which needs additional coding.

+2
source

Source: https://habr.com/ru/post/1695846/


All Articles