- 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.
- DBA攻堅指南:左手Oracle,右手MySQL
- React Native Cookbook
- Network Automation Cookbook
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- 微信公眾平臺開發:從零基礎到ThinkPHP5高性能框架實踐
- Linux Device Drivers Development
- 從零開始學C語言
- Learning AngularJS for .NET Developers
- INSTANT Silverlight 5 Animation
- Mastering Apache Camel
- Groovy 2 Cookbook
- Getting Started with Windows Server Security
- Python編程:從入門到實踐(第2版)
- 移動智能系統測試原理與實踐
- 我跟爸爸學編程:從Python到C++