Memory organisation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Memory organisation

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

15th Apr 2017, 4:20 PM
Ivan
10 Answers
+ 14
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.
15th Apr 2017, 10:31 PM
SoraKatadzuma
SoraKatadzuma - avatar
+ 9
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.
16th Apr 2017, 8:49 AM
SoraKatadzuma
SoraKatadzuma - avatar
+ 8
LMAO, I'm 19 bro😂😂
16th Apr 2017, 9:02 AM
SoraKatadzuma
SoraKatadzuma - avatar
+ 8
@Ivan, precisely
16th Apr 2017, 9:05 AM
SoraKatadzuma
SoraKatadzuma - avatar
+ 8
@SoraKatadzyma that's ......a bit...... too intense =,=.
16th Apr 2017, 9:31 AM
Leon lit
Leon lit - avatar
+ 7
@soraKatadzuma how can u answer soo... intense.... just being 10.... OMG
16th Apr 2017, 9:01 AM
Ronit Kumar
Ronit Kumar - avatar
+ 7
me too....
16th Apr 2017, 9:03 AM
Ronit Kumar
Ronit Kumar - avatar
+ 2
So if i create an instance of a class without the new-operator, it will be put into stack?
16th Apr 2017, 9:04 AM
Ivan
+ 1
where are the variables stored that aren't created with new and aren't local variables in functions?
16th Apr 2017, 8:32 AM
Ivan
0
are these objects also accessed by the stack-pointer?
16th Apr 2017, 1:49 PM
Ivan