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  >  Tech FAQs  >  Programming  >  C
Next Question 
 C  |  Question 1 of 92    Print  
what is the meaning memory allocation & why we use it?

  
Total Answers and Comments: 5 Last Update: November 05, 2007     Asked by: satyajit 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 08, 2006 10:43:29   #1  
Raagu        

RE: what is the meaning memory allocation & why we use...
Memory allocation refers to reserving memory for a variable storage. The variable can be an array or a datastructure.
 
Is this answer useful? Yes | No
February 16, 2007 13:12:04   #2  
       

RE: what is the meaning memory allocation & why we use...
Memory Allocation::According to the conceptual view the program instructions and global and static variable in a permanent storage area and local area variables are stored in stacks. The memory space that is located between these two regions in available for dynamic allocation during the execution of the program. The free memory region is called the heap. The size of heap keeps changing when program is executed due to creation and death of variables that are local for functions and blocks. Therefore it is possible to encounter memory overflow during dynamic allocation process. In such situations, the memory allocation functions mentioned above will return a null pointer. ......Avay
 
Is this answer useful? Yes | No
February 16, 2007 13:20:49   #3  
fcawad_03 Member Since: October 2006   Contribution: 9    

RE: what is the meaning memory allocation & why we use...

Memory Allocation:::According to the conceptual view the program instructions and global and static variable in a permanent storage area and local area variables are stored in stacks. The memory space that is located between these two regions in available for dynamic allocation during the execution of the program.

The free memory region is called the heap. The size of heap keeps changing when program is executed due to creation and death of variables that are local for functions and blocks. Therefore it is possible to encounter memory overflow during dynamic allocation process. In such situations, the memory allocation functions mentioned above will return a null pointer.

Allocating a block of memory: A block mf memory may be allocated using the function malloc. The malloc function reserves a block of memory of specified size and returns a pointer of type void. This means that we can assign it to any type of pointer.

It takes the following form: ptr=(cast-type*)malloc(byte-size); ptr is a pointer of type cast-type the malloc returns a pointer (of cast type) to an area of memory with size byte-size. Example: x=(int*)malloc(100*sizeof(int));

On successful execution of this statement a memory equivalent to 100 times the area of int bytes is reserved and the address of the first byte of memory allocated is assigned to the pointer x of type int Allocating multiple blocks of memory: Calloc is another memory allocation function that is normally used to request multiple blocks of storage each of the same size and then sets all bytes to zero.

The general form of calloc is: ptr=(cast-type*) calloc(n,elem-size); The above statement allocates contiguous space for n blocks each size of elements size bytes. All bytes are initialized to zero and a pointer to the first byte of the allocated region is returned. If there is not enough space a null pointer is returned.

Releasing the used space: Compile time storage of a variable is allocated and released by the system in accordance with its storage class. With the dynamic runtime allocation, it is our responsibility to release the space when it is not required.

The release of storage space becomes important when the storage is limited. When we no longer need the data we stored in a block of memory and we do not intend to use that block for storing any other information, we may release that block of memory for future use, using the free function. free(ptr); ptr is a pointer that has been created by using malloc or calloc.


 
Is this answer useful? Yes | No
July 20, 2007 02:42:32   #4  
Gautam Bhalla        

RE: what is the meaning memory allocation & why we use...

Memory Allocation:--Memory allocation is nothing but allocation of a block of memory or storage register from RAM to keep track of previous instractions or variables we are dealing with.

Need:-Memory allocarion is important to keep the track of current value of the data items and instructions.


 
Is this answer useful? Yes | No
November 05, 2007 08:39:18   #5  
yagnam ramesh babu Member Since: February 2007   Contribution: 10    

RE: what is the meaning memory allocation & why we use...

allocation of memory for a particular variable like is done because to save unusage of memory


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape