- Learning Boost C++ Libraries
- Arindam Mukherjee
- 221字
- 2021-07-16 20:49:03
Chapter 3. Memory Management and Exception Safety
C++ has a great deal of compatibility with the C programming language. C++ retains pointers for representing and accessing specific memory addresses and provides manual memory management primitives via the new
and delete
operators. You can also seamlessly access from C++, the C Standard Library functions and C system calls or platform APIs of most major operating systems. Naturally, C++ code often deals with handles to various OS resources, like heap memory, open files, sockets, threads, and shared memory. Acquiring such resources and failing to release them could have undesirable consequences for your programs, showing up as insidious bugs, including memory leaks and deadlocks.
In this chapter, we look at ways of encapsulating pointers to dynamically-allocated objects using smart pointers to ensure that they are automatically deallocated when they are no longer needed. We then extend these techniques to non-memory resources. In the process, we develop an understanding of what is meant by exception-safe code and use smart pointers to write such code.
These topics are divided into the following sections:
- Dynamic memory allocation and exception safety
- Smart pointers
- Unique ownership semantics
- Shared ownership semantics
For some sections of this chapter, you will need access to a compiler with C++11 support. This will be called out with additional instructions in individual sections.
- Unity Virtual Reality Projects
- 單片機應用技術
- ASP.NET程序設計教程
- PhoneGap:Beginner's Guide(Third Edition)
- C語言程序設計
- 速學Python:程序設計從入門到進階
- Python全棧數據工程師養成攻略(視頻講解版)
- Building Wireless Sensor Networks Using Arduino
- Mastering Akka
- Odoo 10 Implementation Cookbook
- IBM Cognos TM1 Developer's Certification guide
- Application Development with Swift
- WordPress Search Engine Optimization(Second Edition)
- Learning Cocos2d-JS Game Development
- 自己動手構建編程語言:如何設計編譯器、解釋器和DSL