GeekInterview.com
Series: Subject: Topic:
Question: 321 of 827

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

Asked by: Interview Candidate | Asked on: Jun 8th, 2007
Showing Answers 1 - 3 of 3 Answers
neverd

Answered On : Jun 11th, 2007

View all answers by neverd

Program memory includes data memory, stack memory and heap memory and code memory

  
Login to rate this answer.
Sridhar V

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.

Kindly see the memory diagram for C programsLow Memory__________________________CODE MEMORY                             |   (CODE SEGMENT)__________________________|INITIALIZED MEMORY                   |   Initialized adn unintiallized static and ------------------------------------------|   global variables stored hereUNINTIALIZED MEMORY (BSS)      |    (DATA SEGMENT)__________________________|HEAP                                            |    Memory allocated with calloc and malloc__________________________|    stored here                       ||                       /                        /____________||_____________STACK(STACK SEGMENT)              |          Initialized and unintiallized automatic __________________________|           variables store hereHigh Memoryarrow indiacates the growth of memory address as the memory is filledThis diagram shows the use of the CS, DS, SS, ES with regards Aravind Kumar Singh

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.