• 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

 

 

HEAP MEMORY

The heap memory is used to allocate space to the dynamic data. The data whose size can shrink and expand as the requirements vary. We can allocate the extra memory whenever required using command such as malloc(), calloc(), realloc() and de-allocate the space already allocated using command such as free(), delete(). The memory in heap is allocated at the run time.

                We can take HEAP memory as a group of nodes (circles) and every node is reachable only if It has a direct or indirect reference from some root node (pointer) which is stored in STACK memory. When we use memory allocation functions like malloc, calloc or realloc the memory node are selected and linked to the specified root node. Now if we don’t free the nodes of HEAP memory before the root node is de-allocated, the reference to those memory nodes is lost and they become unreachable, hence known as garbage memory or memory leak. Hence to avoid this problem the programmer must free the memory after it’s use.

Advantage: This memory can be anytime shrunk or expanded when ever the requirements of the program changes.

Disadvantage: We have to manually deallocate the memory allocatd using function like free or delete, otherwise the memory which is not deallocated at the proper time goes to the garbage and is not available for re-use.

We can represent the above memories in a diagram as

 

www.exploreroots.com

 

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