Memory management

From Wikipedia for FEVERv2
(Redirected from Dynamic memory allocation)
Jump to navigation Jump to search

"Memory allocation" redirects here. Memory management_sentence_0

For memory allocation in the brain, see Neuronal memory allocation. Memory management_sentence_1

This article is about memory management in an address space. Memory management_sentence_2

For Management of physical memory, see Memory management (operating systems). Memory management_sentence_3

Memory management is a form of resource management applied to computer memory. Memory management_sentence_4



Several methods have been devised that increase the effectiveness of memory management. Memory management_sentence_7


The quality of the virtual memory manager can have an extensive effect on overall system performance. Memory management_sentence_9

Details Memory management_section_0

In some operating systems, e.g., DOS/360 and successors, OS/360 and successors, allocation of storage within an address space is handled by the operating system; in, e.g., Unix-like operating systems, allocation within an address space is at the application level. Memory management_sentence_10

Memory management within an address space is generally categorized as either automatic memory management, usually involving garbage collection, or manual memory management. Memory management_sentence_11

Dynamic memory allocation Memory management_section_1

See also: C dynamic memory allocation Memory management_sentence_12


Memory requests are satisfied by allocating portions from a large pool of memory called the heap or free store. Memory management_sentence_14



The allocator's metadata can also inflate the size of (individually) small allocations. Memory management_sentence_17

This is often managed by chunking. Memory management_sentence_18

The memory management system must track outstanding allocations to ensure that they do not overlap and that no memory is ever "lost" (i.e., that there are no "memory leaks"). Memory management_sentence_19

Efficiency Memory management_section_2

The specific dynamic memory allocation algorithm implemented can impact performance significantly. Memory management_sentence_20

A study conducted in 1994 by Digital Equipment Corporation illustrates the overheads involved for a variety of allocators. Memory management_sentence_21


Implementations Memory management_section_3



Fixed-size blocks allocation Memory management_section_4

Main article: Memory pool Memory management_sentence_25




Buddy blocks Memory management_section_5

Further information: Buddy memory allocation Memory management_sentence_29



If a smaller size is requested than is available, the smallest available size is selected and split. Memory management_sentence_32

One of the resulting parts is selected, and the process repeats until the request is complete. Memory management_sentence_33


When a block is freed, it is compared to its buddy. Memory management_sentence_35


Slab allocation Memory management_section_6

Main article: Slab allocation Memory management_sentence_37

This memory allocation mechanism preallocates memory chunks suitable to fit objects of a certain type or size. Memory management_sentence_38

These chunks are called caches and the allocator only has to keep track of a list of free cache slots. Memory management_sentence_39

Constructing an object will use any one of the free cache slots and destructing an object will add a slot back to the free cache slot list. Memory management_sentence_40

This technique alleviates memory fragmentation and is efficient as there is no need to search for a suitable portion of memory, as any open slot will suffice. Memory management_sentence_41

Stack allocation Memory management_section_7

Main article: Stack-based memory allocation Memory management_sentence_42

Many Unix-like systems as well as Microsoft Windows implement a function called alloca for dynamically allocating stack memory in a way similar to the heap-based malloc. Memory management_sentence_43

A compiler typically translates it to inlined instructions manipulating the stack pointer. Memory management_sentence_44

Although there is no need of manually freeing memory allocated this way as it is automatically freed when the function that called alloca returns, there exists a risk of overflow. Memory management_sentence_45

And since alloca is an ad hoc expansion seen in many systems but never in POSIX or the C standard, its behavior in case of a stack overflow is undefined. Memory management_sentence_46

A safer version of alloca called _malloca, which reports errors, exists on Microsoft Windows. Memory management_sentence_47

It requires the use of _freea. Memory management_sentence_48

gnulib provides an equivalent interface, albeit instead of throwing an SEH exception on overflow, it delegates to malloc when an overlarge size is detected. Memory management_sentence_49

A similar feature can be emulated using manual accounting and size-checking, such as in the uses of alloca_account in glibc. Memory management_sentence_50

Automatic variables Memory management_section_8

Main article: Automatic variable Memory management_sentence_51

In many programming language implementations, all variables declared within a procedure (subroutine, or function) are local to that function; the runtime environment for the program automatically allocates memory for these variables on program execution entry to the procedure, and automatically releases that memory when the procedure is exited. Memory management_sentence_52

Special declarations may allow local variables to retain values between invocations of the procedure, or may allow local variables to be accessed by other procedures. Memory management_sentence_53

The automatic allocation of local variables makes recursion possible, to a depth limited by available memory. Memory management_sentence_54

Garbage collection Memory management_section_9

Main article: Garbage collection (computer science) Memory management_sentence_55

Garbage collection is a strategy for automatically detecting memory allocated to objects that are no longer usable in a program, and returning that allocated memory to a pool of free memory locations. Memory management_sentence_56

This method is in contrast to "manual" memory management where a programmer explicitly codes memory requests and memory releases in the program. Memory management_sentence_57

While automatic garbage has the advantages of reducing programmer workload and preventing certain kinds of memory allocation bugs, garbage collection does require memory resources of its own, and can compete with the application program for processor time. Memory management_sentence_58

Systems with virtual memory Memory management_section_10

Main articles: Memory protection and Shared memory (interprocess communication) Memory management_sentence_59

Virtual memory is a method of decoupling the memory organization from the physical hardware. Memory management_sentence_60

The applications operate on memory via virtual addresses. Memory management_sentence_61

Each attempt by the application to access a particular virtual memory address results in the virtual memory address being translated to an actual physical address. Memory management_sentence_62

In this way the addition of virtual memory enables granular control over memory systems and methods of access. Memory management_sentence_63

In virtual memory systems the operating system limits how a process can access the memory. Memory management_sentence_64



Shared memory is one of the fastest techniques for inter-process communication. Memory management_sentence_67

Memory is usually classified by access rate into primary storage and secondary storage. Memory management_sentence_68


Memory management in OS/360 and successors Memory management_section_11

IBM System/360 does not support virtual memory. Memory management_sentence_70

Memory isolation of jobs is optionally accomplished using protection keys, assigning storage for each job a different key, 0 for the supervisor or 1–15. Memory management_sentence_71

Memory management in OS/360 is a supervisor function. Memory management_sentence_72

Storage is requested using the GETMAIN macro and freed using the FREEMAIN macro, which result in a call to the supervisor (SVC) to perform the operation. Memory management_sentence_73

In OS/360 the details vary depending on whether the system is generated for PCP, MFT or MVT. Memory management_sentence_74

In OS/360 MVT, suballocation within a job's region or the shared System Queue Area (SQA) is based on subpools, areas a multiple of 2 KB in size—the size of an area protected by a protection key. Memory management_sentence_75

Subpools are numbered 0–255, plus an unnumbered subpool used to store loaded programs. Memory management_sentence_76

Within a region subpools are assigned either the job's storage protection or the supervisor's key, key 0. Memory management_sentence_77

Subpools 0–126 receive the job's key. Memory management_sentence_78

Initially only the unnumbered subpool and subpool zero are created, and all user storage requests are satisfied from subpool 0, unless another is specified in the memory request. Memory management_sentence_79

Subpools 250–255 are created by memory requests by the supervisor on behalf of the job. Memory management_sentence_80

Most of these are assigned key 0, although a few get the key of the job. Memory management_sentence_81

MFT uses fixed partitions redefinable by the operator instead of dynamic regions and PCP has only a single partition. Memory management_sentence_82

Each subpool is mapped by a list of control blocks identifying allocated and free memory blocks within the subpool. Memory management_sentence_83

Memory is allocated by finding a free area of sufficient size, or by allocating additional blocks in the subpool, up to the region size of the job. Memory management_sentence_84

It is possible to free all or part of an allocated memory area. Memory management_sentence_85

The details for OS/VS1 are similar to those for MFT and the details for OS/VS2 are similar to those for MVT, except that the page size is 4 KiB. Memory management_sentence_86

For both OS/VS1 and OS/VS2 the shared System Queue Area (SQA) is nonpageable. Memory management_sentence_87

In MVS the address space includes an additional pageable shared area, the Common Storage Area (CSA), and an additional private area, the System Work area (SWA). Memory management_sentence_88

Also, the storage keys 0-7 are all reserved for use by privileged code. Memory management_sentence_89

See also Memory management_section_12

Memory management_unordered_list_0

Credits to the contents of this page go to the authors of the corresponding Wikipedia page: management.