Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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?

Share this post

Link to post
Share on other sites
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: map
X + 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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!