| |||||||||
memory storage for use in a computer program during the runtime of that program. Memory is typically allocated from a large pool of all available unused memory called the heap, but may also be allocated from multiple pools. A dynamically allocated object remains allocated until it is deallocated explicitly, either by the programmer or by an garbage collector; this is notably different from automatic and static memory allocation. We say that such an object has dynamic free lists
The main problem for most dynamic memory allocation algorithms is to avoid both internal or external fragmentation while keeping both allocation and deallocation efficient. Also, most algorithms in use have the problem that a large number of small allocations can cause wasted space due to collecting metadata; thus most programmers avoid this.
Dynamic allocation of some kind is directly supported in almost all programming languages. The malloc function is used to dynamically allocate memory in C. The new operator is used to dynamically allocate memory in C++ and Java.