Boost smart pointers

Source: Internet
Author: User
Tags intel pentium

 

Smart pointers

Reprinted: http://boost.ez2learn.com/libs/smart_ptr/smart_ptr.htm

Introduction
Common requirements common requirements
Exception safety Safety
Exception-Specifications
History and acknowledgements history and Sense
References references

Introduction

Smart pointers is the object that refers to the object that stores the object that points to the Dynamic Allocation (on the stack. Their behavior is similar to the internal creation of C ++, but they can automatically remove the object they point to at the time of registration. Intelligence refers to the role that a brain plays in common scenarios. It can ensure that a complete analysis structure of an image is automatically allocated. It can also be used to allocate objects to the dynamic images shared with multiple hosts.

In terms of concept, intelligence refers to an object that can be viewed as an object that points to it. Therefore, when an object is no longer needed, intelligence refers to Division of the object.

Intelligence refers to five provided by zookeeper (five in the original article). How can I count as six? Intelligent refers to classification templates:

Scoped_ptr <Boost/scoped_ptr.hpp> The only ownership of a single object. You cannot copy a volume.
Scoped_array <Boost/scoped_array.hpp> The unique ownership of a Data Group. You cannot copy a volume.
Shared_ptr <Boost/shared_ptr.hpp> All rights to images shared among multiple objects.
Shared_array <Boost/shared_array.hpp> All rights to a data group shared between multiple devices.
Weak_ptr <Boost/weak_ptr.hpp> AShared_ptrThe observer who does not have all rights to the object.
Intrusive_ptr <Boost/intrusive_ptr.hpp> Share all rights of the object with an intrusive reference.

These templates are designed to be used for chargeSTD: auto_ptrThe template is insufficient.

They are in Bjarne stroustrup's "The C ++ programming language" Third Edition, 14.4, resource Acquisition is initialization described in the resource Source Management Section ("the obtained resource is initialization ", in the Chinese version of C ++ programming language, "resource application is initialized", and the individual thinks it is not accurate-the author's note.

Zookeeper Program
Smart_ptr_test.cpp, used to perform the exact operation.

Network compatibility (compatibility) combined with boost intelligence refers to the previous version of zookeeper, which describes some changes that smart refers to earlier versions.

The smart pointer timings (smart refers to the peak time) of the website is used to note the performance issues of the peak traffic.

Smart pointer Programming Techniquesshared_ptrAnd
weak_ptrFor some high-performance applications.

Common requirements common requirements

These smart templates have a unique number of templates.TIt specifies the type of the object pointed to by the smart finger. If the type isTOrOperator DeleteGenerally, intelligence refers to the definition of the workflow template.

When smart refers to intelligent intelligence,TIt can be an incomplete type. Unless otherwise specified, smart refers to real-sample scenarios, which requireTIs a complete type. In practice, we need to compile all examples of this requirement, including the missing parts of incomplete types. SeeChecked_deleteDescription of the function template.

Note,Shared_ptrWithout this restriction, most of its members are not requiredTIs a complete type.

Basic Principles of rationale

TThe requirement is to carefully and carefully construct the maximum security, and also allow the handle-body (also called pimpl (pimpl full attention to "pointer to implementation ", optional valid C ++, 3rd edition item 25 29 and 31-Author's note) and other similar usage. In these scenarios, a smart finger can appearTIs an incomplete metadata unit. In this way, the interface is extracted from the actual memory and stored in the memory units used by the interface. The example described in the specific intelligence refers to the application of the intelligence refers to in these usage.

Note: During structure analysis,Scoped_ptrRequirementsTIs a complete type, and
Shared_ptr
Not required.

Exception safety Safety

These intelligence refers to the number of consecutive functions specified as "no shadow" or "no shadow" except for this ". This means that when a pair of objects in these categories Appears normally, the whole program maintains the variable before the constant function is used. This is equivalent to the fact that the security certificate has no side effects that may occur. Other types of data are always unique. Which of the following functions can be used to generate a typical function?TMeeting common requirements) is limitedSTD: bad_allocIn addition, it is limited to those who confirm in the text that
STD: bad_alloc.

Exception-Specifications

No general rules are used.
Exception-specification rationale.

All Smart refers to templates that contain the numbers of members who never quit frequently, because they never quit frequently, in addition, the other data used by them will not be frequently used. This function is labeled as follows:// never throws.

The damage indicator points to the category-type function of the image.

History and acknowledgements history and Sense

May January 2002. Peter DIMOV has reviewed all four categories, added features, modified bugs, and split them into four single-sheet header files, and addedWeak_ptr. For the summary of these changes, see the compatibility website.

May 2001. The Vladimir prus proposal requires a complete type during the analysis. I have discussed some of the improvements in analytics, including Dave Abrahams, Greg Colvin, beman Dawes, Rainer deyke, Peter DIMOV, John Maddock, Vladimir prus, Shankar Sai, and others.

May November 1999. Darin Adler providesOperator =,Operator! =, AndSTD: swapAnd
STD: lessIs specific to shared type.

May September 1999. Luis Coelho providesShared_ptr: swapAndShared_array: swap.

May 1999. In April 1999 and May, Valentin Bonnard and David Abrahams proposed a large number of proposals, leading to major improvements.

May October 1998. Beman Dawes proposed originalSafe_ptrAndCounted_ptrThe original values under the name are per Anderson, Matt austern, Greg Colvin, Sean corfield, Pete Becker, Nico josutis, Dietmar kühl, Nathan Myers, chichiang Wan and Judy Ward. After discussion, the four new categories of names have been finalized, and it is determined that the standards do not need to be followed.STD: auto_ptr
And finally finalized the standards and definitions of different types of data.

In the next three months,Shared_ptrIn
For more information, see the boost.org component list. In fact, the theoretical points are beginning to indicate the reference data that must be held, whether it is to attach it to the object to which it points, or Shard to other places. These differences have their own two major changes:

  • Direct segmentation: shared_ptr contains a pointer to the object and a pointer to the number.
  • Duration: shared_ptr contains a pointer pointing to the helper object, which then contains a pointer pointing to the object and the number.
  • Embedded attaching: The number is a member pointing to the object.
  • Placement attaching: the additional data volume is controlled by operator new.

Each real-time technique has both poor performance and poor performance. We calculated the amount of time for direct and inter-method operations, and found that at least a tiny difference was found on the Intel Pentium chip. Kevlin Henney provides his own article "counted body techniques ". Dietmar kühl proposed a special technology that allows the use of the template that they prefer to implement, and implemented it.

However, Greg Colvin and Jerry Schwarz thought that "digital transformation will prevent users from using the plug-in", and most importantly, we chose to provide direct implementation.

Summer 1994. Greg Colvin proposed to the C ++ Standards CommitteeAuto_ptrAndCounted_ptrAnd what we are talking about nowScoped_ptrAnd
Shared_ptrVery similar. [Col-94] in one of the few cases where the whole Committee did not accept the proposal of the Community,Counted_ptrNo, and unexpectedly add all rights authority to copyrightAuto_ptr.

References references

[Col-94] GREGORY Colvin,
Exception safe smart pointers, C ++ Committee document 94-168/n0555, July, 1994.

[E & D-94] John R. Ellis & David L. detlefs,
Safe, efficient garbage collection for C ++, usenix proceedings, February, 1994. This paper extends des an extensive discussion of weak pointers and an extensive bibliography.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.