UMBC CS 201, Fall 05
UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | lectures | news | help

Why use Dynamic Memory Allocation

When working with arrays, we have always had to estimate the size we expect the array to be. Many times we'll overestimate and waste a lot of space since underestimating the size of an array is disastrous. Now we can actually wait until the program is executing and ask the user how much space is needed or get the size information from a file. This allows us to use exactly the amount of space required.

Both malloc() and calloc() are used for dynamic memory allocation. You may use whichever one you like best.

When using dynamic memory allocation, you must remember that you are now in charge of the memory that you've allocated and when you are finished using it, you should release it using the function free().

CSEE | 201 | 201 F'05 | lectures | news | help

Monday, 26-Sep-2005 11:20:30 EDT