0

Why C++ has 2 memories? And why should I use the 2 memories???

27th Jan 2017, 8:50 PM
Rana Rony
Rana Rony - avatar
3 Answers
+ 1
Are you talking about stack vs. heap?
9th Feb 2017, 11:26 PM
Steven Ramey
0
Yes please could you answer me ??
11th Feb 2017, 12:40 AM
Rana Rony
Rana Rony - avatar
0
Both stack and heap are in RAM. However, accessing the stack is much faster than accessing the heap. This is why we use pointers in C++. If I create a pointer to an object 'Enemy' as below: Enemy* myEnemy = new Enemy(); Then we can do things much more quickly by passing around the address of myEnemy rather than a copy of the entire object. The 'new' keyboard says to allocate new memory on the heap. Also, the stack is used to keep track of which subroutine the logic should return to after execution is completed (in a function for example).
11th Feb 2017, 11:31 AM
Steven Ramey