• 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-III:

 free(x);

www.exploreroots.com

Now there ia no memory allocated to the pointer x and hence if now we try to use the memory then it may cause ERROR as we’ll referencing to the deallocated memory. Now one may ask that what the problem in referencing that memory is. Actually as we have de-allocated the memory, the operating system can allocate that space to some other proess and then if we refer to that space then it may cause a serious ERROR. HOW CAN WE AVOID THIS PROBLEM? We can avoid this problem by putting NULL to the pointer after de-allocating the memory as shown:

free(x);

x= NULL; So that now if we mistakenly try to refer to the memory then it causes no serious problem.

Char* z= (char*)calloc(3, sizeof(char));                         SIZE OF CHAR WE TAKE AS 1 BYTE.

Calloc() function is same as malloc() but it also initializes the allocated memory to zero. Hence 3 bytes are allocated from the HEAP memory and zero (0) is stored in the allocated memory 2006 – 2008 and starting address is stored in the pointer z.

www.exploreroots.com

 

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