-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
C++ Memory Management
By :
Before we get to the memory allocation mechanisms of C++, let’s first take a brief look at the C family of memory allocation functions through its most distinguished representatives: malloc() and free(). There are, of course, many other memory-allocation-related functions such as calloc(), realloc(), and aligned_alloc(), not counting operating-system-specific services that perform similar tasks for specialized use cases, but these will serve our discussion well.
Note that since this is a book on memory management with C++, I will use the C++ version of these functions (from <cstdlib> instead of <stdlib.h>), which really changes nothing to the code we will write except for the fact that in C++, these functions are located in the std namespace.
The signatures for these two functions are as follows:
void* malloc(size_t n); void free(void *p);
Quick tip: Enhance your coding experience with the AI Code...