when a class is in the Heap, where are its members?

Started by
0 comments, last by Noggs 13 years, 4 months ago
hi,

a question that torments me for so much time.

Suppose I'm at the main() function and NEWed a class on the heap.

X x = new X;

and this X class holds inside itself many huge data structures like maps, sets, vectors, etc. But they are all declared like this

class X {
std::map< z, w> map;
std::vector< z> vec;

};

let's supposed they are filled and HUGE. Where are they located? in the Heap of the in the Stack?
Advertisement
The map and vec objects will be located on the heap at a small offset from X. The actual data inside the map and vector objects is allocated from the heap as well, but could be anywhere.

This is how your X class might be laid out in memory:

X + 0:                 mapX + sizeof(map<z,w>):  vec


If you do sizeof(map<z,w>) in your debugger you will see how big that object is. That will never change regardless of how much data you store in it.

This topic is closed to new replies.

Advertisement