Difference between program memory, data memory, stack memory and heap memory?

Showing Answers 1 - 5 of 5 Answers

Sridhar V

  • Jul 9th, 2007
 

When the program is compiled and linked different parts of the program is organised in seperate segments. That is our code will be in one segment code means the instructions to be executed this is called as code segment or program memory this is usually readonly. Then there are datas which on which the code operates,these datas get stored in a segment called data segment. Stack memory is a part of programs memory which will be used as stack in case of function calls to store the IP and parameters variables of the current function. The three types of memory specified above are owned by the corresponding process or program the linker will give info abt where to store which data to the loader, based on these infos loader will load the corresponding image i.e executable in the memory.

Heap memory is the memory which is not owned by the process. OS has set of pages of memory which can be allocated to the process when a process requests for extra memory, these requests are done by the malloc and calloc function calls. This memory is allocated when the program is running and according to the current condition of the process i.e allocated dynamically thats y this is called as dynamic allocation.

I have used words program and process invariably. Because a program needs physical primary memory when it gets executed and a program under execution is a process, Hope this explanation is clear.

kindly see the memory diagram for C programs

Low Memory
__________________________
CODE MEMORY                             |   (CODE SEGMENT)
__________________________|
INITIALIZED MEMORY                   |   Initialized adn unintiallized static and
------------------------------------------|   global variables stored here
UNINTIALIZED MEMORY (BSS)      |    (DATA SEGMENT)
__________________________|
HEAP                                            |    Memory allocated with calloc and malloc
__________________________|    stored here
                       ||
                       /

                        /
____________||_____________
STACK(STACK SEGMENT)              |          Initialized and unintiallized automatic
__________________________|           variables store here


High Memory

arrow indiacates the growth of memory address as the memory is filled

This diagram shows the use of the CS, DS, SS, ES

with regards

Aravind Kumar Singh

  Was this answer useful?  Yes

mukesh patil

  • Aug 4th, 2014
 

Data memory = where you place your variables. You can read and write values.
Program memory = where the application is stored. Some chips allows parts of the program memory to be modified in blocks (segments), but you cant store variables in the program memory. It is normally possible to store constants - i.e. initialized variables that you do not change - in the program memory.
Your PC also has data memory and program memory. But the program memory is very small in the PC - it is just for storage of the BIOS - the boot messages you see when the PC boots, and (often, but not always) the configuration pages where you define if you have a floppy installed, if the computer should support a USB keyboard etc.

  Was this answer useful?  Yes

Amol Patil

  • Aug 4th, 2014
 

program memory:where place your variable,you can read and write values
data memory:where tee application is stored some chips allows part of the program memory to be modified in block
,but you cant store a variable in the program memory.means initilize variable is not change in program memory.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions