In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains how C++ uses make_shared to build shared_ptr-managed objects, which interested friends may wish to have a look at. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how C++ uses make_shared to build shared_ptr-managed objects.
Using make_shared to build objects managed by shared_ptr
Reason (reason)
Make_shared gives a more concise statement of the construction. It also gives an opportunity to eliminate a separate allocation for the reference counts, by placing the shared_ptr's use counts next to its object.
Make_shared provides a more concise expression for construction actions. Because it puts the count of shared_ptr after the object, using it also provides an opportunity to reduce another increase in count.
Example (sample)
Void test () {
/ / OK: but repetitive; and separate allocations for the Bar and shared_ptr's use count
Shared_ptr p {new Bar {7}}
Auto Q = make_shared (7); / / Better: no repetition of Bar; one object
} Enforcement (implementation recommendations)
Flag the repetitive usage of template specialization list
Prompt for reuse of template specialization parameter list
Flag variables declared to be shared_ptr
Prompts you to use shared_ptr to define variables directly.
At this point, I believe you have a deeper understanding of "how C++ uses make_shared to build shared_ptr-managed objects". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.