Memory Management (C++)

Free Store
A standard C++ array data structure is fixed in size once it's created. The size is specified with a constant at compile time. Sometimes it's useful to determine the size of an array dynamically at execution time and then create the array. This is known as dynamic memory management and is performed with the operators new and delete.

You can use the new operator to dynamically allocate the exact amount of memory required to hold an object or array at execution time. Objects allocated by new are said to be "on the free store" (also, to be "heap objects", or "allocated in dynamic memory"). Once memory is allocated in the free store, you can access it via the pointer that operator new returns. When you no longer need the memory, you can return it to the free store by using the delete operator to deallocate the memory, which can then be reused by future new operations.

The "plain" operator delete is used to delete individual objects; delete [] is used to delete all elements in an array.