Dynamic memory allocation
|
Missing image Merge_articles.png | It has been proposed that this article or section be merged with Memory allocation.
This request may be discussed on the article's talk page. |
Dynamic memory allocation is the allocation of 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 a garbage collector; this is notably different from automatic and static memory allocation. We say that such an object has dynamic lifetime.
The problem of fulfilling an allocation request, which involves finding a block of unused memory of a certain size in the heap, is a difficult problem. A wide variety of solutions have been proposed, including:
The main problem for most dynamic memory allocation algorithms is to avoid both internal and 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, sometimes by using a strategy called chunking.
Language support
Dynamic allocation of some kind is supported in almost every mainstream programming language. The malloc
function is used to dynamically allocate memory in C. A new
operator or keyword is used to dynamically allocate memory in Ada, C++, Pascal and Java.
External links
- "Scalable Lock-Free Dynamic Memory Allocation (http://www.research.ibm.com/people/m/michael/pldi-2004.pdf)" (173 KB) by Maged M. Michael
- lock-free heap manager (http://www.leapheap.com/)de:Heap (Speicher)