Jump to content

Memory allocation

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 217.244.1.131 (talk) at 06:48, 17 June 2005 (See also...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.

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).

See also