Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top