next up previous contents
Next: Pointers Up: Advanced Discussion Previous: Assignment (Extra Credit 200   Contents


Dynamically Allocated Memory and Pointers

At this point, we only store information into variables and parameters. Both variables and parameters are ``named'' with identifiers. While this is sufficient for most programs, variables and parameters have certain limitations.

One problem with variables, including global array variables, is that memory may not be efficiently utilized. For example, if we need to handle the processing of ``who is taking what class'' in memory, we need to reserve enough memory for the maximum number of students, the maximum number of classes and the maximum number of enrollments per class.

While this can be done, it is a waste of memory space. This is because in most cases, we do not need the maximum allocation. Reserving more memory than necessary is, in general, no a big problem. However, if enough applications running on a computer is doing this, a computer can quickly run out of memory.

Dynamically allocated memory helps to solve this problem by reserving memory ``on-the-fly'' only when more memory is needed. This way, an application only needs just enough memory to get the job done. Even better, this method allows a program to deallocate memory when it is no longer needed. When utilized correctly, a program using dynamically allocated memory puts a minimal demand on systems resources while getting the job done.



Subsections
next up previous contents
Next: Pointers Up: Advanced Discussion Previous: Assignment (Extra Credit 200   Contents
Tak Auyeung 2003-12-03