GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  Deallocation of memory

Answer: When we allocates the memory using malloc() and calloc(), it returns pointer pointing to the base address to the allocated memory. But while freeing the memory we call free(pointer) then

How the operation system knows that how much memory is about to be free.


June 06, 2009 04:40:05 #3
 amarnathsatrawala   Member Since: June 2009    Total Comments: 3 

RE: Deallocation of memory
 

Dynamic memory is allocated on heap. De-allocation is counterpart of the
allocation operation. the task of allocation and De-allocation is handled by the
base/standard libraries. These store information about the allocated memory like
base address and size. initially all of heap is free.


Many implementations are possible. e.g the free space may be maintained in a
free list and the the allocated memory in a doubly linked list or hash table.


Memory can only be requested to be de-allocated with the same address which
was returned during the allocation.


Fragmentation of the free space is a known problem. a request for allocation
may fail even when there is enough memory available in the heap. it may be due
to the non-availability of a contiguous chunk of memory at least equal to the
size of the requested size.


Automatic heap management strategy e.g. garbage collection alleviate some of
the problems with better utilization of the heap memory.

     

 

Back To Question