Spiegato, Home

Technology and Gadgets

What Is Dynamic Memory Allocation?

  • Published by Spiegato
  • 2 min read

Dynamic memory allocation, also called heap-based memory allocation, is a type of memory management that is sharply contrasted by static memory allocation. In dynamic memory allocation, the programmer tells the computer exactly how much memory to allocate for each program and how long to hold onto the memory. This solves many of the issues that occur in static memory allocation, such as overuse of memory and stalled programs. While it solves many issues, if the programmer forgets to tell the memory to dump, then the dynamic memory can become an issue.

Computers, by default, use static memory allocation. This means the memory holds onto programs when they are used, even if the program is no longer being used or if the held memory becomes dangerous or an obstacle for performance. For example, if the user stops running a program that takes 2 megabytes (MB) on a 3 MB machine, and a second program needs another 2 MB, the second program will not work. This is because there is not enough memory left in the computer for the other program.

With static memory allocation, the user or programmer cannot specify the amount of memory he or she wants stored, nor can the programmer tell the static memory to dump the memory to free up resources. This is why advanced users often use dynamic memory allocation. The programmer is able to control everything about the memory, including how long to hold onto resources.

For example, the programmer can set dynamic memory allocation to hold onto only 1 MB, or less, which would save enough system memory to allow other programs to open. This can be done because the static memory usually holds onto everything about the program, while dynamic memory allows programmers to set it at a lower value that holds some data, but not everything. At the same time, static memory will still be needed, and it can be set in this allocation schema.

A potential problem with dynamic memory allocation — one that rarely comes into play — is that the dynamic memory may fill up if the programmer forgets to set a time value. If no time value is set, unlike static memory that will eventually release the memory, dynamic memory will hold onto the information. If the program has a garbage dump application, and most do, it will activate after a certain amount of time to clear the memory. It is still best practice to set a time value for the memory allocation.

Key terms in this article

Related articles

  • What Is Dynamic Bandwidth Allocation?

    Dynamic bandwidth allocation is a term used to describe the method of allocating bandwidth on a network on an as-needed basis. With this process…

  • What Is Dynamic Video Memory Technology?

    Dynamic video memory technology is a method of performing active-time scaling of video memory in order to provide the most efficient graphical performance…

  • What is Dynamic Random Access Memory?

    Dynamic random access memory, or DRAM, is the most common type of computer memory. It is particularly useful for computers as it can hold a lot of data in…

  • What is a File Allocation Table?

    A File Allocation Table (FAT) is a system used by computers in order to store file information. Where this information is stored can range from an…

  • What Is Dynamic Imaging?

    The term “dynamic imaging” refers to a variety of imaging technologies, spanning personal and professional uses. The term usually relates to the…