Wednesday

Dynamic memory allocation


Dynamic memory allocation 


Dynamic memory allocation is the practice of assigning memory locations to variables during execution of the program by explicit request of the programmer. Dynamic allocation is a unique feature to C (amongst high level languages). It enables us to create data types and structures of any size and length to suit our programs need within the program.

                 For example, to use arrays, dynamic memory allocation and use, eliminating the need to determine the size of the array at declaration time. What do I say it is that extra space does not have to. Areas that could use up to 1000 minutes, but you know, actually do not know how much is used, the worst case, might well end up without one. In such cases, to specify precisely the number of elements in the declaration is a very difficult time. If too much waste of memory, and the less accessible outside of the array, may result in an error.

                 Dynamically allocated memory is freed when finished should not be used without. When released, this area no longer use that system to manage memory (OS) and I'll tell it to. When you exit the program without a release, essentially freed automatically. But I say with certainty, it should be freed by calling a dedicated function explicitly.

                 Finally, the dynamically allocated memory area, the area is secured in a location different from the usual definition of a variable. There is also the name depending on the role of memory space and just go. Used in the dynamic memory allocation area is called the heap. In contrast, the variables are usually allocated to the location of the stack. Variables are allocated on the heap, even if it was secured out of the scope, continues to exist. For example, in function, if you create a dynamic variable, but missing out the function and will continue to exist on the heap.

                  The functions malloc (), realloc (), calloc () and free (), the Library functions stdlib.h, malloc.h or are responsible for this task. All data are stored in the free store (heap), which is limited to 64k a stack in the beginning, this varies from machine. All variables were declared so far on the stack, now you tell me where to go, in an indirect way.

                 The following functions are used in c for purpose of memory management.

 

Kindly Bookmark this Post using your favorite Bookmarking service:
Technorati Digg This Stumble Stumble Facebook Twitter
YOUR ADSENSE CODE GOES HERE

0 comments:

Post a Comment

Dont Forget for Commets

 

| C programing tutorials © 2009. All Rights Reserved | Template Style by My Blogger Tricks .com | Design by Brian Gardner | Back To Top |