Containers in memory

As you already know from the previous chapters, an object takes memory space on one of the memory segments provided to the process. Most of the time, we are interested in the stack or heap memory. An automatic object takes space on the stack. The following two declarations both reside on the stack:

struct Email {  // code omitted for brevity};int main() {  Email obj;  Email* ptr;}

Although ptr represents a pointer to an Email object, it takes space on the stack. It can point to a memory location allocated on the heap, but the pointer itself (the variable storing the address of a memory location) resides on the stack. This is crucial to understand and remember before going further with vectors and lists.

As we saw earlier ...

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.