Tuesday, July 20, 2010

Difference between Stack and Heap

Stack

It used by value type. It can store fixed amout of data and stored in RAM.

Stack is used by Int, Array, Enumerator, Struct. Memory management is automatically done by program so we dont need to create desctructor.

Heap

It is Used by reference type. It has unlimited size. Data whose size can not be determined before execution of program and need to allocate dynamically in run time are fall in this category. For example if we need to read data of file then it may have any size so this type of date are stored in heap. It is stored in secondary memory i.e. harddisk.

String, Classes use heap for storing data. Program doesnot about memory status of heap so programmar him/herself need to destruct it.

No comments:

Post a Comment