In the previous recipe, we've learned how to manage dynamic memory (allocated on the heap) in a very convenient way, by using unique_ptr. We've learned as well that unique_ptr must be used, just in case of exclusive ownership of the memory, or resources managed by the memory. But what if we have a resource that is co-owned by more entities? What if the memory we have to manage has to be released when all the owners have completed their job? Well, this is exactly the use case for shared_ptr. Just as with unique_ptr, for shared_ptr we don't have to allocate memory with new, but there is a template function (part of the C++ standard library), make_shared.
United States
Great Britain
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Singapore
Hungary
Ukraine
Luxembourg
Estonia
Lithuania
South Korea
Turkey
Switzerland
Colombia
Taiwan
Chile
Norway
Ecuador
Indonesia
New Zealand
Cyprus
Denmark
Finland
Poland
Malta
Czechia
Austria
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Netherlands
Bulgaria
Latvia
South Africa
Malaysia
Japan
Slovakia
Philippines
Mexico
Thailand