Memory organisation | Sololearn: Learn to code for FREE!


Memory organisation

How is memory organised when programming c++? what is dynamic and static memory? Where is it saved?


4/15/2017 4:20:29 PM


10 Answers

New Answer


I like this question, Memory in C++ is organized into 3 categories. The stack, the heap and the text. The stack is used to push functions on top of each other creating scopes, but it also is a small memory reserve for those functions. Local variables use this memory. The heap is a place where uninitialized variables get there memory. Anytime you use the "new" keyword or make a call to a memory function in cstdlib, you are getting memory from the heap. The text is literally just text, this is the part of the program that holds your declarations, and all the text of your program. The stack is considered static memory, because it is set, and doesn't change. And the heap would be dynamic memory because it is always changing. All the memory is loaded into either the RAM of your computer or one of the three caches of your computer.


Globals, which I assume is what you're referring to, are like locals. When the program starts anything it finds globally are automatically pushed to the stack and will stay there until the program ends.


LMAO, I'm 19 broπŸ˜‚πŸ˜‚


@Ivan, precisely


@SoraKatadzyma that's ......a bit...... too intense =,=.


@soraKatadzuma how can u answer soo... intense.... just being 10.... OMG


me too....


So if i create an instance of a class without the new-operator, it will be put into stack?


where are the variables stored that aren't created with new and aren't local variables in functions?


are these objects also accessed by the stack-pointer?