Step by Step

Tuesday, May 17, 2011

Stack and Heap


There are two places where your data can be on
1-Stack
2-Heap
*Stack
Where your static data saved in it
Like integer as we now that the integer size is 8 bytes
Also like Array as we set its size at declaration
-So to read from it you actually go to the address in stack and read data directly
Ok that's sound good, what about Array List [like array but its size is variables]
So we need huge place to can save our data in that case [as we didn't know how much of bytes we need]
To solve that we need to use heap
*Heap
undetermined space to save our data in it
But as our data is variable we need pointer for that place.
 We save pointer for data in stack and actual data in heep
-So to read from it you actually go to the address in stack and take the indirect address
Then with that address go to heap to read your data

0 comments: