Is there a limit in the maximum number of std::shared_ptr managed objects per process?

Asking this because there is a maximum number of mutexes per process. If the implementation of std::shared_ptr is using mutex, isn't there a similar limit in the number of objects managed objects?

An answer discussing mutex-based and atomic-operation-base implementations is more than welcome.

有帮助吗?

解决方案

Generally no, there is no limit because the shared_ptr implementations on common OS's do not use mutexes under the hood (they use atomic increment/decrement functions). Also, an implementation could, for example, choose to manage all reference count accesses with a single mutex. Might be slow in some cases, but it could work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top