Skip to main content
gamedev.net
🔒 Locked

Heap or Stack ?

Started by Endemoniada Jan 13, 2005 at 12:25 AM 4 replies 1k views
Original Post
Endemoniada
Endemoniada
Hi guys, Look at this simple example: class CStuff { public: int m_data[256]; }; // create class in heap memory CStuff* pStuff=new CStuff; Is m_data also created in heap memory ? Thanks.
nife
nife
new and delete (as their counterparts malloc and free) are using the heap.
Killers don't end up in jailThey end up on a high-score!
Zahlman
Zahlman
Yes. The m_data is part of the chunk of memory that is allocated when new a CStuff.
blizzard999
blizzard999
The only way to 'allocate' data on the stack is create an instance of something in the function body.

void function(void){  char buffer[256]; // stack  CStuff c; //stack sizeof(CStuff)==256   //and so on}
Zipster
Zipster
Well, there's technically _alloca that allocates from the stack instead of the heap. But I've personally never used it.

Topic Locked

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

Sign in to reply to this topic.