Memory Management and Smart Pointers
Memory management can be defined as a process in which a computer’s memory is managed – for example, assigning memory to programs, variables, and more – so that it doesn’t affect the overall performance. Sometimes, the computer’s data can range up to terabytes, so efficiently using memory is necessary to minimize memory wastage and boost performance.
Memory management and smart pointers come at a price in C++. Programmers often complain about C++ because of its manual memory management requirements. While languages such as C# and Java use automatic memory management, it makes the programs run slower than their C++ counterparts. Manual memory management is often error-prone and unsafe. As we already saw in the previous chapters, a program represents data and instructions. Almost every program uses computer memory to some extent. It’s hard to imagine a useful program that doesn’t require memory allocation...