Dynamic memory allocation From Wikipedia, the free encyclopedia In computer science, dynamic memory allocation (also known

as heap-based memory allocation) is the allocation of memory storage for use in a computer program during theruntime of that program. It can be seen also as a way of distributing ownership of limited memory resources among many pieces of data and code. Dynamically allocated memory exists until it is released either explicitly by the programmer, or by the garbage collector. This is in contrast to static memory allocation, which has a fixed duration. It is said that an object so allocated has a dynamic lifetime. Contents [hide]

1 Details 2 Efficiency 3 Implementations

o o

3.1 Fixed-size-blocks allocation 3.2 Buddy blocks

4 See also 5 External links 6 Further reading 7 References [edit]Details

The task of fulfilling an allocation request consists of finding a block of unused memory of sufficient size. 

Problems during fulfilling allocation request 

Internal and external fragmentation. 

Reduction needs special care, thus making implementation more complex (see algorithm efficiency).

Allocator's metadata can inflate the size of (individually) small allocations; 

Chunking attempts to reduce this effect.

Usually, memory is allocated from a large pool of unused memory area called the heap (also called the free store). Since the precise location of the allocation is not known in advance, the memory is accessed indirectly, usually via a pointer 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 below. [edit]Efficiency

When a block is freed. the allocator will start with the smallest sufficiently large block avoiding needlessly breaking blocks) [edit]See also               Automatic memory allocation Dynamic array Garbage collection Hazard pointer Heap overflow Hoard memory allocator Java Virtual Machine heap malloc Memory pool mmap new (C++) obstack Slab allocation Stack-based memory allocation . One of the halves is selected. If they are both free. In this system. also called memory pool allocation. they are combined and placed in the next-largest size buddy-block list. it is compared to its buddy. it is broken in two. All the blocks of a particular size are kept in a sorted linked list or tree. see Buddy memory allocation. If the block is more than twice as large as desired. (When a block is allocated. and the process repeats (checking the size again and splitting if needed) until the block is just large enough.The dynamic memory allocation algorithm actually used can impact performance significantly and a study conducted in 1994 by Digital Equipment Corporation illustrates the overheadsinvolved for a variety of allocators. This works well for simple embedded systems. The lowest average instruction path length required to allocate a single memory slot was 52 (as measured with an instruction level profiler on a variety of software) [edit]Implementations [1] [edit]Fixed-size-blocks allocation Main article: memory pool Fixed-size-blocks allocation. [edit]Buddy blocks For more details on this topic. uses a free list of fixed-size blocks of memory (often all of the same size). memory is allocated from a large block in memory that is a power of two in size.

^ http://www. related reading or external links. but its sources remain .cs.ubc.pdf This article includes a list of references.[edit]External links     Sample bit-mapped arena memory allocator in C TLSF: a constant time allocator for real-time systems Slides for knowing about Dynamic memory allocation Inside A Storage Allocator [edit]Further reading  "Dynamic Storage Allocation: A Survey and Critical Review". Department of Computer Sciences University of Texas at Austin [edit]References 1.ca/local/reading/proceedings/spe91-95/spe/vol24/issue6/spe895.

Sign up to vote on this title
UsefulNot useful