Short introduction: I am working on multithread code and I have to share dynamically allocated objects between two threads. To make my code cleaner (and less error-prone) I want to explicitly "delete" objects in each thread and that's why I want to use shared_ptr
.
First question:
I want to know if implementation of -> operator
in shared_ptr
has some extra overhead (e.g. larger then unique_ptr
) during run time. Objects I am talking about are usually longlife instances copied only once after creation (when i distribute them between threads), then I only access these objects' methods and fields.
I am aware, that shared_ptr
only protect reference counting.
Second question:
How well are shared_ptr
optimized in libstdc++? Does it always use mutex or take advantage of atomic operations (I focus on x86 and ARM platforms)?