shared_ptr 从原始指针构造时是否分配?

Does shared_ptr allocate when constructed from raw pointer?

据我了解shared_ptr它包含一个指向控制块的指针,该控制块包含原始指针强计数和弱计数。

我处于需要无锁分配的情况,所以我可以从池分配的内存中分配一个原始指针,然后使用自定义删除器创建一个唯一指针以将其放回池中,所以还不错。

在 shared_ptr 的情况下,但是如果我使用这些原始指针和自定义分配器之一构造共享指针,它会在那个点分配控制块吗?

如果是,有没有办法以无锁方式为控制块提供内存?

In the case of a shared_ptr however if I construct a shared pointer with one of these raw pointers and custom allocators does it allocate the control block at that point?

是的。

If it does is there a way to provide the memory for the control block in a lock-free way?

shared_ptr 的构造函数具有接受自定义分配器的重载。

参考some shared_ptr documentation.

(我不是很清楚whether the deleter will also be allocated by your custom allocator。)