• Home
  • Tutorials
  • Interviews
  • Info Seed
  • Forums
  • Projects
  • Links
  • Contact Us
C Language
C POINTERS
MEMORY MANAGEMENT
INTRODUCTION
FIXED MEMORY
STACK MEMORY
HEAP MEMORY
Illustration with simple program
Functions to manage HEAP MEMORY
MEMORY ALLOCATION
MEMORY ALLOCATION-II
MEMORY ALLOCATION-III
MEMORY ALLOCATION-IV
Illustrations of MEMORY ALLOCATION
Illustration I
Illustration-I Contd..
Illustration-I Contd..
Illustration-I Contd..
Illustration II
Illustration-II Contd..
Illustration-II Contd..
Illustration III
Illustration IV
FRAME POINTER

 

 

MEMORY ALLOCATION-ILLUSTRATION-II

 Now we have to picturize the whole scenario in HEAP and STACK memory.

Ans: We have no dynamically allocated variables in this program. Hence there is not much role of HEAP memory. We analyze the memory allocation and de-allocation in STACK on next page. We know stack memory is used to store local variables and the return address pointer, frame pointer (the pointer which is used to point to the starting of the frame just below) and other registers.

                The global variable ‘a’ with value 2 is stored in the fixed memory and the memory remains allocated till the program execution ends.

Now as we enter into main, a frame is created in the stack. Next with the statement int x= func2(5), memory is reserved for the local variable x in the stack.

www.exploreroots.com

Now we have a function call to function func2 hence a new frame is created and firstly return address to main is stored in the stack. Next we have to allocate a space for variable n which is a parameter of the function func2() and 5 is stored. After this another local variable k is allocated space in stack with random value.

www.exploreroots.com

 

previous next
| Copyright © 2009 exploreroots- All Rights Reserved | Disclaimer |