Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Difference between stack mamory and heap memory? (http://www.go4expert.com/forums/difference-stack-mamory-heap-memory-t23282/)

salonibhutani86 12Sep2010 18:53

Difference between stack mamory and heap memory?
 
what is the difference between stack mamory and heap memory?

LordN3mrod 12Sep2010 21:26

Re: question
 
Well, first of all, I think you should have googled it, and THEN, if you had any questions posted them here... but hey! :)

So, an object can have either automatic(stack) or dynamic(heap, or, more formally, free store) storage duration. There is also a third type of storage, that is, static storage, but I won't talk about it at the moment.

Any object created with 'new' is created on the heap, that means, its lifetime won't end until the program ends, or you explicitly call delete. On the other hand, any local object that was not created with 'new' is created on the stack, and its lifetime ends as soon as the control goes out of the block the variable was declared in.

Again, better google it

singhsan02 22Sep2010 17:08

Re: Difference between stack mamory and heap memory?
 
DiD you meant Heap and Free Store are same? I guess its not the same.

LordN3mrod 23Sep2010 15:02

Re: Difference between stack mamory and heap memory?
 
The C++ standard does not say anything about a 'stack' or a 'heap'. It operates with terms 'automatic' and 'dynamic'. The standard does not mandate how new be implemented, it only mandates the behaviour. There is a logical reason why automatic memory should be called a stack - that is because nested scopes are a stack in a sense. On the other hand I see no connection between a heap the data structure and a heap the memory. That's why I personally prefer the term free store. And yes, the free store and the heap is exactly the same thing in this context. Do you disagree?


All times are GMT +5.5. The time now is 16:56.