• 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

Now we have the following statements and we see how STACK & HEAP memory is allocated to different variables. We have the empty HEAP memory & STACK memory as:

NOTE: For this question we have used a heap memory & allocated space serially while in real, memory is allocated randomly by operating system.

www.exploreroots.com

 

Char* x;

x= (char*)malloc(2);

Char* y= (char*)malloc(4);

free(x);

Char* z= (char*)calloc(3, sizeof(char));

free(y);

free(z);

 

Now we represent the HEAP and STACK memory after each statement.

Char* x;

Assuming X would occupy 4-bytes for storing address. Hence 4 bytes are allocated for x in the STACK but only some random value that is already preset at the allocated memory gets stored in the pointer.

www.exploreroots.com

 

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