Chapter 11. Allocating Memory in C++

<feature>
  • Understand the differences between allocating memory statically and dynamically

  • Learn about the stack and the free store

  • Discover the new and delete operators

  • See how you can dynamically allocate arrays

  • Learn to handle dynamic memory allocation errors

  • Find out how you can create your own new and delete operators

</feature>

Allocating Static Memory

When you declare a predesignated number of variables for a program to use during its execution, you are working with static memory. Static memory is reserved by the compiler at compile time. Let’s say you are planning to use an array of structures to represent employee data in a program, for example:

struct Employee { char FirstName[15]; char LastName[20]; float ...

Get Practical 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.