Difference between the Stack and the Heap


#1

Hello,
I try always to understand the things how it works, instead of understanding the syntax of the language, I didn’t understand the difference between the heap and the stack , and where are they , I now the Ram the Cache … maybe because I am a French native speaker , but any explanation will be welcome :slight_smile:

Annonces en Tunisie


#2

To an Objective-C programming, the stack is where local (or automatic) variables are stored. The heap is where objects live.


#3

Hello,
Thank you for your answer :slight_smile: it makes sens now , and both of them physically in RAM ?

Annonces en Tunisie


#4

That’s actually a surprisingly deep question.

As far as you need to know for the next two years, the answer is “Yes.”

(The true answer is “probably”)


#5

All,

Here is a good source for understanding memory, the Stack and the Heap:

http://masters-of-the-void.com/book5.htm


#6

Thank you for that link Kotaro! That helped me tons!


#7

Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer’s RAM .

Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it’s allocation is dealt with when the program is compiled.

Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory .

More…Stack and Heap

Watson