Memory allocation
|
Missing image Merge_articles.png | It has been proposed that this article or section be merged with Dynamic memory allocation.
This request may be discussed on the article's talk page. |
Memory allocation, in computer science, is the act of allocating memory to a program for its usage, typically for storing variables, code or data. Memory allocation is a widely discussed topic in the field of operating systems, as computers have limited memory, and many programs need memory to run. To find out more, you can look up on the various memory allocation algorithms and techniques that can be used.
Contents |
Allocation techniques
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 RTOS's, they are also used in conventional operating systems (such as the Linux kernel).