| Dynamic Memory Allocation |
Article Index for Dynamic |
Website Links For Dynamic |
Information AboutDynamic Memory Allocation |
| CATEGORIES ABOUT DYNAMIC MEMORY ALLOCATION | |
| memory management | |
|
The task 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 . FIXED-SIZE-BLOCKS ALLOCATION One solution is to have a LIFO Linked List of fixed size blocks of memory. This works astonishingly well for simple Embedded Systems . BUDDY BLOCKS Another solution is to have a '' Binary Buddy Block Allocator ''. In this system, memory is allocated from a large block of memory that is a Power Of Two in size. If the block is more than twice as large as desired, it is broken in two. One of the halves is selected, and the process repeats (checking the size again and splitting if needed) until the block is just large enough. All the buddies of a particular size are kept in a sorted linked list or Tree . When a block is freed, it is compared to its buddy. If they are both free, they are combined and placed in the next-largest size buddy-block list. (When a block is allocated, the allocator will start with the smallest sufficiently large block avoiding needlessly breaking blocks) Note that buddy block allocators are not unique to Real-time Operating Systems , they are also used in conventional operating systems (such as the Linux kernel). HEAP-BASED MEMORY ALLOCATION In heap-based memory allocation, memory is allocated from a large pool of unused memory area called the ''heap'' (this has nothing to do with the Heap data structure). The size of the memory allocation can be determined at run-time, and the lifetime of the allocation is not dependent on the current procedure or stack frame. The region of allocated memory is accessed indirectly, usually via a Reference . The precise algorithm used to organize the memory area and allocate and deallocate chunks is hidden behind an abstract interface and may use any of the methods described above. In constrast, the Call Stack memory is usually of limited size and the lifetime of the allocation depends on the duration of the corresponding functions. SEE ALSO
REFERENCES
|
|
|