The function malloc in C ANSI libraries allows you to allocate memory in specific sizes to accommodate dynamic memory allocation. The concept of dynamic memory allocation is that variables and data structures are stored in memory areas that are allocated, reallocated and freed from the program's instructions during execution. A word processor is a good example of this. As lines are typed in, the characters are stored in arrays ( or some other structure) allocated in memory dynamically. This keeps the program from making extra accesses to the disk drives. Once the document is ready to be stored (Save), the memory is read into the file on disk. Then, since the memory is no longer needed to hold the document (New or Exit), the memory is released back for use by other documents or programs. It is released by the function free in C. It is also used with the functions calloc, realloc, farmalloc, farcalloc. Search for more information on each of these. I hope that this helps you understand the function and the why and how of dynamic memory allocation as well.
2006-09-04 06:33:13
·
answer #1
·
answered by Anonymous
·
0⤊
0⤋
malloc dynamicaly (@ run time) allocates memory. it can be used efficiently with pointers. the memory is allocated when the compiler executes the code at run time;
enjoy c language................
2006-09-04 04:19:32
·
answer #2
·
answered by Anonymous
·
0⤊
0⤋