How it works...

In C++, there are three different ways to declare a variable:

  • Global variables: These are variables that are globally accessible. On Linux, these usually exist in the .data, .rodata, or .bss sections of your executable.
  • Stack variables: These are variables that you define inside functions and reside in your application's stack memory, which is managed by the compiler.
  • Heap variables: These are variables that are created using malloc()/free() or new()/delete() and use heap memory that is managed by a dynamic memory management algorithm (for example, dlmalloc, jemalloc, tcmalloc, and so on).

In this chapter, we will focus on the latter, that is, heap style memory allocation. You might already know that, in C++, memory is allocated ...

Get Advanced C++ Programming Cookbook 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.