Memory Management and Smart Pointers

Memory management comes at a price in C++. Concerned programmers often complain about C++ because of its manual memory management requirements. While languages like 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 have already seen 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.

Memory allocation and deallocation starts with the simplest call of a function. Calling a function usually implies passing arguments to it. The function ...

Get Expert C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.