- 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.
- HTML5+CSS3王者歸來
- Ray分布式機器學(xué)習:利用Ray進行大模型的數(shù)據(jù)處理、訓(xùn)練、推理和部署
- Practical Windows Forensics
- 好好學(xué)Java:從零基礎(chǔ)到項目實戰(zhàn)
- Python圖形化編程(微課版)
- Python+Tableau數(shù)據(jù)可視化之美
- Scala編程(第5版)
- Raspberry Pi Robotic Projects(Third Edition)
- Hands-On Kubernetes on Windows
- ASP.NET 4.0 Web程序設(shè)計
- Practical GIS
- 算法圖解
- Learning D
- Python編程入門(第3版)
- Python無監(jiān)督學(xué)習