Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by draconar Dec 1, 2010 at 7:02 PM 0 replies 800+ views
Original Post
draconar
draconar
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?
Noggs
Noggs
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) in your debugger you will see how big that object is. That will never change regardless of how much data you store in it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.