zoukankan      html  css  js  c++  java
  • 内存管理(memory allocation内存分配)

    Memory management is the act of managing computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when no longer needed. This is critical to any advanced computer system where more than a singleprocess might be underway at any time.[1]

    内存管理的关键是提供动态分配程序要求的内存,不需要时释放它。

    Several methods have been devised that increase the effectiveness of memory management. Virtual memory systems separate the memory addresses used by a process from actual physical addresses, allowing separation of processes and increasing the effectively available amount of RAM using paging or swapping to secondary storage. The quality of the virtual memory manager can have an extensive effect on overall system performance.

    dynamic memory allocation:

    The task of fulfilling an allocation request consists of locating a block of unused memory of sufficient size. Memory requests are satisfied by allocating portions from a large pool of memory called the heap or free store. At any given time, some parts of the heap are in use, while some are "free" (unused) and thus available for future allocations. Several issues complicate implementation, such as external fragmentation, which arises when there are many small gaps between allocated memory blocks, which invalidates their use for an allocation request. The allocator's metadata can also inflate the size of (individually) small allocations. This is managed often by chunking. The memory management system must track outstanding allocations to ensure that they do not overlap and that no memory is ever "lost" as a memory leak.

    Efficiency[edit]

    The specific dynamic memory allocation algorithm implemented can impact performance significantly. A study conducted in 1994 by Digital Equipment Corporation illustrates the overheads involved for a variety of allocators. The lowest averageinstruction path length required to allocate a single memory slot was 52 (as measured with an instruction level profiler on a variety of software).[2]

    Implementations[edit]

    Since the precise location of the allocation is not known in advance, the memory is accessed indirectly, usually through a pointer reference. The specific algorithm used to organize the memory area and allocate and deallocate chunks is interlinked with the kernel, and may use any of the following methods:

    因为事先不知道分配的精确位置,内存被间接的访问。通常通过一个pointer reference,指令的算法用来管理内存通常和内核有关,可以使用以下的算法:

    Fixed-size blocks allocation[edit]

    Fixed-size blocks allocation, also called memory pool allocation, uses a free list of fixed-size blocks of memory (often all of the same size). This works well for simple embedded systems where no large objects need to be allocated, but suffers from fragmentation, especially with long memory addresses. However, due to the significantly reduced overhead this method can substantially improve performance for objects that need frequent allocation / de-allocation and is often used in video games.

    内存池分配,使用free-list来实现,这个工作良好在简单的嵌入式系统(没有large object需要分配),但是会产生碎片,特别是很长的内存地址,

    Memory pools中文意思为内存池, ,内存池(Memory Pool)是一种内存分配方式。 通常我们习惯直接使用new、malloc等API申请分配内存,这样做的缺点在于:由于所申请内存块的大小不定,当频繁使用时会造成大量的内存碎片并进而降低性能。 内存池则是在真正使用内存之前,先申请分配一定数量的、大小相等(一般情况下)的内存块留作备用。当有新的内存需求时,就从内存池中分出一部分内存块,若内存块不够再继续申请新的内存。这样做的一个显著优点是尽量避免了内存碎片,使得内存分配效率得到提升。

    Buddy blocks[edit]

    In this system, memory is allocated into several pools of memory instead of just one, where each pool represents blocks of memory of a certain power of two in size. All blocks of a particular size are kept in a sorted linked list or tree and all new blocks that are formed during allocation are added to their respective memory pools for later use. If a smaller size is requested than is available, the smallest available size is selected and halved. One of the resulting halves is selected, and the process repeats until the request is complete. When a block is allocated, the allocator will start with the smallest sufficiently large block to avoid needlessly breaking blocks. 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.

    slab allocation algorithm

    更多:

    http://cuiyongxiu.com/tag/vs2010

  • 相关阅读:
    get请求数据
    ajax (详细)
    DedeCMS去掉友情链接中“织梦链投放”“织梦链”的方法
    Metro UI CSS可以快速创建一个Windows 8风格的网站
    CSS实现垂直居中的5种方法
    解决jQuery冲突 noConflict
    dedecms pic_scroll.js和jquery-1.9.1.min.js
    js和jquery下拉菜单全攻略
    IE6、IE7、IE8、FireFox css line-height兼容问题
    IE开发利器-IE10中的F12开发者工具
  • 原文地址:https://www.cnblogs.com/youxin/p/3693255.html
Copyright © 2011-2022 走看看