Effective C ++, 3rd edition, Chapter 3. Resource Management)

Source: Internet
Author: User

Chapter 3. Resource Management (Resource Management)

By Scott Meyers

Translator: fatalerror99 (itepub's nirvana)

Release: http://blog.csdn.net/fatalerror99/

Resource is something like this: once you stop using it, you need to return it to the system. If you do not do this, it will do nothing without harm. In C ++ProgramMedium, the most commonly used resource is dynamically allocated memory (dynamically allocated memory) (if you allocate memory but never release it, it will lead to memory leak (Memory leakage) consequences ), however, memory is only one of many resources that you must manage. Other common resources include file descriptors (file descriptor), mutex locks, fonts and brushes in graphical user interfaces (guis ), database connections (database connection) and network Sockets (network socket ). Regardless of the resource, releasing it is very important when you no longer use it.

It is difficult to make sure that this is done by hand under any conditions, but when you consider exceptions, a function with multiple return paths, without fully understanding the impact of the modifications he made, he should change the maintenance programmer of the software and handle resource management) this situation becomes very clear when the special methods are inadequate.

This chapter is based on C ++'s support for constructors, Destructors, and copying operations, object-based (Object-based) Resource management method. Experience shows that strict adherence to this method can eliminate almost all resource management problems. Next, we will move this chapter to the item focusing on Memory Management (memory management. These subsequent items supplement the previous more general items, because the objects (object) for memory management must know how to work correctly.

This chapter includes the following content. Click to open it:

Item 13: use objects to manage resources

Item 14: Think carefully about copying behavior in Resource-managing classes

Item 15: Provide access to raw resources in Resource-managing classes

Item 16: use the same form in corresponding uses of new and delete

Item 17: store newed objects in smart pointers in standalone statements

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.