尿蛋白高不能吃什么食物| 线差是什么意思| 化工厂是干什么的| 右侧卵巢内囊性结构什么意思| 阿托伐他汀钙片有什么副作用| 什么是汛期| 小龙虾和什么不能一起吃| 晚上十二点是什么时辰| 吃什么药能来月经| 多此一举是什么生肖| 左眼一直跳是什么原因| 撮鸟是什么意思| 胰岛素抵抗是什么| 一个火一个华念什么| 派对是什么意思| 包饺子什么馅好吃| 为什么医生很少开阿斯美| 猪苓是什么东西| 楚国什么时候灭亡的| 肺主皮毛是什么意思| 好逸恶劳什么意思| 什么是介入治疗| 发泡胶用什么能洗掉| 夏天受凉感冒吃什么药| 曩是什么意思| 超管是什么| 喝牛奶就拉肚子是什么原因| 1933年属什么生肖| 泛化是什么意思| 女装什么牌子好| 十月十三是什么星座| hpv16是什么意思| 风流是什么意思| 八月一日是什么日子| 栓是什么意思| 朱迅和朱军是什么关系| 75是什么意思| 炼乳是什么东西| 老是掉头发是什么原因| 早期教育是什么专业| 去肝火喝什么茶| 化作风化作雨是什么歌| 肝火旺吃什么好| 睡觉经常流口水是什么原因| 绚丽夺目的意思是什么| 吃什么能减肥最快还能减全身| 你最喜欢的食物是什么| 天秤女和什么星座最配| 80年出生属什么生肖| s.m是什么意思| 1995年出生属什么| 血压低吃什么中成药| 花痴是什么意思| 脑白质稀疏什么意思| 用什么药材泡酒最好| 家道中落是什么意思| 红细胞分布宽度偏低是什么原因| 活血化瘀吃什么| 夫妇是什么意思| 为什么十二生肖老鼠排第一| 造影有什么危害| 女生有美人尖代表什么| 为什么空调外机会滴水| 色盲色弱是什么意思| 白配什么颜色好看| 1958年属什么生肖| 抽血抽不出来是什么原因| 发冷发热是什么原因| 小孩睡觉流口水是什么原因| 怡字五行属什么的| 梦见生肉是什么征兆| 什么是矢量| 龟头有红点用什么药| ct与核磁共振有什么区别| 左卡尼汀口服溶液主要治疗什么| 宫颈异常是什么意思| 宫颈炎是什么原因引起的| 支气管病变什么意思| 夏天吃什么汤| 农历六月十七是什么日子| 省军区司令员是什么级别| 经常出汗是什么原因| 做胃镜有什么好处| 首战告捷什么意思| 9月13号是什么星座| 鱼腥草长什么样| 梦见家里水管漏水是什么意思| 为什么割包皮| 宜子痣是什么意思| 方形脸适合什么发型| 公安局跟派出所有什么区别| 农历九月五行属什么| pad是什么设备| 女人吃什么对卵巢和子宫好| 红指什么生肖| 腰椎退行性变什么意思| 中专什么时候报名| 冬天什么| 口唇发绀是什么意思| 脸上发麻是什么原因| 白带什么时候来| 鱼油有什么作用| 盐的主要成分是什么| π是什么意思| 日久生情是什么意思| 胃痉挛吃什么药最有效| 1960年属鼠的是什么命| 月经老是推迟是什么原因| 喉咙溃疡吃什么药| 清炖羊肉放什么调料| 上嘴唇发黑是什么原因| 三陪是什么| 屁股出汗多是什么原因| 命里缺什么怎么看| 场景是什么意思| nars属于什么档次| 为什么会甲状腺肿大| 没有淀粉可以用什么代替| 结肠炎吃什么药治疗效果好| 转氨酶升高有什么症状| 令人发指是什么意思| 增强ct是什么| 淋球菌阳性是什么意思| 益生元是什么东西| 小孩子注意力不集中看什么科| 晚上喝红酒有什么好处和坏处| 为什么会遗精| 老年人脸肿是什么原因引起的| 什么动物| 什么的小院| 脚二拇指比大拇指长代表什么| 多愁善感是什么意思| b像什么| 手抖头抖是什么病| 做小月子要注意什么| 尾巴翘上天是什么意思| 手臂长斑是什么原因| 足癣用什么药最快好| 上海有什么好玩的地方适合小孩子| fda是什么意思| 梦见自己家盖房子是什么预兆| 逍遥丸配什么治失眠| 全托是什么意思| 冰心的原名叫什么| 什么食物含蛋白质高| 收获颇丰什么意思| 为什么要长征| 丁五行属什么| 截石位是什么意思| 世袭罔替什么意思| 肝是什么器官| 红景天是什么药| 眼睛模糊是什么原因引起的| 什么手机电池最耐用| 落叶像什么飘落下来| 肝弥漫性病变是什么意思| 耳垂后面疼是什么原因| 寻常疣用什么药膏除根| 什么鸡不能吃| 山药有什么营养| 叫花子是什么意思| 什么叫造影| 脂蛋白a是什么| 有什么有什么| 为什么会突然长体癣| 为什么会呕吐| 价值连城是什么意思| 低血压不能吃什么食物| 头皮上长疣是什么原因造成的| 没有精液是什么原因| 三碘甲状腺原氨酸高是什么意思| 为什么要补钾| 果葡糖浆是什么| 过敏嘴唇肿是什么原因| nt和无创有什么区别| 尿胆原高是什么原因| 榕字五行属什么| 什么家庭不宜挂八骏图| 10月7号是什么星座| 容貌是什么意思| 用盐洗头发有什么好处| 胆是起什么作用的| 查询电话号码拨打什么| 希腊脚是什么意思| 61岁属什么生肖| 豆腐鱼是什么鱼| 蚯蚓用什么呼吸| 第二学士学位是什么意思| 百分点是什么意思| 客源是什么意思| 夜未央是什么意思| 拜观音菩萨有什么讲究| 冠状沟有白色分泌物是什么原因| 咽炎吃什么药好| c肽是什么| 抗美援朝是什么时候| 耳鸣是什么原因| 保胎吃什么食物好| 什么人适合喝三七粉| 有没有什么| 胚芽米是什么米| 胃酸是什么| 全身皮肤痒是什么原因| 儿童坐飞机需要什么证件| hpv用什么药| 干咳吃什么食物好| 男人吃什么壮阳| 大兴什么| 阴茎勃起不硬吃什么| 榴莲什么时候吃是应季| 员工体检费计入什么科目| 手凉是什么原因| 爱是什么歌曲| 9.27日是什么星座| 什么叫cta检查| 赢字五行属什么| 稽留流产什么意思| 造势是什么意思| 肩膀痛是什么原因| 12月是什么星座的| 梦见撒尿是什么意思| 榴莲什么时候最便宜| 渗透压是什么| 八八年属什么生肖| 土豆可以做什么美食| 59岁生日有什么讲究| 事业编制是什么意思| 什么叫tct检查| 半斤八两什么意思| 发改委是做什么的| 记性越来越差是什么原因| 吠陀是什么意思| 什么是音程| 滋养是什么意思| 肛门塞什么东西最舒服| 用减一笔是什么字| 10月2号是什么星座| 重力是什么| 东莞五行属什么| 推介是什么意思| 私募是做什么的| 吃什么补肝养肝最有效| 我会送你红色玫瑰是什么歌| 靖国神社是什么地方| 糖尿病是什么原因引起的| 结婚 为什么| 椰子不能和什么一起吃| 近视眼底改变什么意思| 倒着走路有什么好处| 2022年是什么生肖| 电表走的快是什么原因| 美国为什么不敢打伊朗| 枭神夺食会发生什么| 低热是什么症状| 1938年属什么生肖| 肺有问题会出现什么症状| 扑救带电火灾应选用什么灭火器| 毛尖属于什么茶| 肺大泡吃什么药| 干细胞有什么作用| 手术后吃什么恢复快| 速战速决的意思是什么| 高频是什么意思| 送长辈什么礼物合适| 百度Jump to content

中国杯惨败,里皮直言犯了两个错误:集训和首发都选错了人

From Wikipedia, the free encyclopedia
(Redirected from Heap (programming))
百度 明天白天,全省晴间多云明天夜间到26日,全省晴转多云。

Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of resource management applied to 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 single process 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 size of the virtual address space beyond the 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. The system allows a computer to appear as if it may have more memory available than physically present, thereby allowing multiple processes to share it.

In some operating systems, e.g. Burroughs/Unisys MCP,[2] and OS/360 and successors,[3] memory is managed by the operating system.[note 1] In other operating systems, e.g. Unix-like operating systems, memory is managed at the application level.

Memory management within an address space is generally categorized as either manual memory management or automatic memory management.

Manual memory management

[edit]
An example of external fragmentation

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[note 2] of memory called the heap[note 3] 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. In the C language, the function which allocates memory from the heap is called malloc and the function which takes previously allocated memory and marks it as "free" (to be used by future allocations) is called free. [note 4]

Several issues complicate the 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 often managed by chunking. 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").

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 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).[1]

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:

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 and deallocation, and so it is often used in video games.

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, or blocks of some other convenient size progression. 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 split. One of the resulting parts 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 correspondingly larger-sized buddy-block list.

Slab allocation

[edit]

This memory allocation mechanism preallocates memory chunks suitable to fit objects of a certain type or size.[5] These chunks are called caches and the allocator only has to keep track of a list of free cache slots. 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. 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.

Stack allocation

[edit]

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. A compiler typically translates it to inlined instructions manipulating the stack pointer.[6] 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. 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.

A safer version of alloca called _malloca, which reports errors, exists on Microsoft Windows. It requires the use of _freea.[7] gnulib provides an equivalent interface, albeit instead of throwing an SEH exception on overflow, it delegates to malloc when an overlarge size is detected.[8] A similar feature can be emulated using manual accounting and size-checking, such as in the uses of alloca_account in glibc.[9]

Automated memory management

[edit]

The proper management of memory in an application is a difficult problem, and several different strategies for handling memory management have been devised.

Automatic management of call stack variables

[edit]

In many programming language implementations, the runtime environment for the program automatically allocates memory in the call stack for non-static local variables of a subroutine, called automatic variables, when the subroutine is called, and automatically releases that memory when the subroutine is exited. Special declarations may allow local variables to retain values between invocations of the procedure, or may allow local variables to be accessed by other subroutines. The automatic allocation of local variables makes recursion possible, to a depth limited by available memory.

Garbage collection

[edit]

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. This method is in contrast to "manual" memory management where a programmer explicitly codes memory requests and memory releases in the program. While automatic garbage collection 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.

Reference counting

[edit]

Reference counting is a strategy for detecting that memory is no longer usable by a program by maintaining a counter for how many independent pointers point to the memory. Whenever a new pointer points to a piece of memory, the programmer is supposed to increase the counter. When the pointer changes where it points, or when the pointer is no longer pointing to any area or has itself been freed, the counter should decrease. When the counter drops to zero, the memory should be considered unused and freed. Some reference counting systems require programmer involvement and some are implemented automatically by the compiler. A disadvantage of reference counting is that circular references can develop which cause a memory leak to occur. This can be mitigated by either adding the concept of a "weak reference" (a reference that does not participate in reference counting, but is notified when the area it is pointing to is no longer valid) or by combining reference counting and garbage collection together.

Memory pools

[edit]

A memory pool is a technique of automatically deallocating memory based on the state of the application, such as the lifecycle of a request or transaction. The idea is that many applications execute large chunks of code which may generate memory allocations, but that there is a point in execution where all of those chunks are known to be no longer valid. For example, in a web service, after each request the web service no longer needs any of the memory allocated during the execution of the request. Therefore, rather than keeping track of whether or not memory is currently being referenced, the memory is allocated according to the request or lifecycle stage with which it is associated. When that request or stage has passed, all associated memory is deallocated simultaneously.

Systems with virtual memory

[edit]

Virtual memory is a method of decoupling the memory organization from the physical hardware. The applications operate on memory via virtual addresses. 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.[10] In this way the addition of virtual memory enables granular control over memory systems and methods of access.

In virtual memory systems the operating system limits how a process can access the memory. This feature, called memory protection, can be used to disallow a process to read or write to memory that is not allocated to it, preventing malicious or malfunctioning code in one program from interfering with the operation of another.

Even though the memory allocated for specific processes is normally isolated, processes sometimes need to be able to share information. Shared memory is one of the fastest techniques for inter-process communication.

Memory is usually classified by access rate into primary storage and secondary storage. Memory management systems, among other operations, also handle the moving of information between these two levels of memory.

Memory management in Burroughs/Unisys MCP systems[2]

[edit]

An operating system manages various resources in the computing system. The memory subsystem is the system element for managing memory. The memory subsystem combines the hardware memory resource and the MCP OS software that manages the resource.

The memory subsystem manages the physical memory and the virtual memory of the system (both part of the hardware resource). The virtual memory extends physical memory by using extra space on a peripheral device, usually disk. The memory subsystem is responsible for moving code and data between main and virtual memory in a process known as overlaying. Burroughs was the first commercial implementation of virtual memory (although developed at Manchester University for the Ferranti Atlas computer) and integrated virtual memory with the system design of the B5000 from the start (in 1961) needing no external memory management unit (MMU).[11]:?48?

The memory subsystem is responsible for mapping logical requests for memory blocks to physical portions of memory (segments) which are found in the list of free segments. Each allocated block is managed by means of a segment descriptor,[12] a special control word containing relevant metadata about the segment including address, length, machine type, and the p-bit or ‘presence’ bit which indicates whether the block is in main memory or needs to be loaded from the address given in the descriptor.

Descriptors are essential in providing memory safety and security so that operations cannot overflow or underflow the referenced block (commonly known as buffer overflow). Descriptors themselves are protected control words that cannot be manipulated except for specific elements of the MCP OS (enabled by the UNSAFE block directive in NEWP).

Donald Knuth describes a similar system in Section 2.5 ‘Dynamic Storage Allocation’ of ‘Fundamental Algorithms’.[disputeddiscuss]

Memory management in OS/360 and successors

[edit]

IBM System/360 does not support virtual memory.[note 5] 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 in OS/360 is a supervisor function. 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.

In OS/360 the details vary depending on how the system is generated, e.g., for PCP, MFT, MVT.

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. Subpools are numbered 0–255.[13] Within a region subpools are assigned either the job's storage protection or the supervisor's key, key 0. Subpools 0–127 receive the job's key. Initially only subpool zero is created, and all user storage requests are satisfied from subpool 0, unless another is specified in the memory request. Subpools 250–255 are created by memory requests by the supervisor on behalf of the job. Most of these are assigned key 0, although a few get the key of the job. Subpool numbers are also relevant in MFT, although the details are much simpler.[14] MFT uses fixed partitions redefinable by the operator instead of dynamic regions and PCP has only a single partition.

Each subpool is mapped by a list of control blocks identifying allocated and free memory blocks within the subpool. 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. It is possible to free all or part of an allocated memory area.[15]

The details for OS/VS1 are similar[16] to those for MFT and for MVT; the details for OS/VS2 are similar to those for MVT, except that the page size is 4 KiB. For both OS/VS1 and OS/VS2 the shared System Queue Area (SQA) is nonpageable.

In MVS the address space[17] includes an additional pageable shared area, the Common Storage Area (CSA), and two additional private areas, the nonpageable local system queue area (LSQA) and the pageable System Work area (SWA). Also, the storage keys 0–7 are all reserved for use by privileged code.

See also

[edit]

Notes

[edit]
  1. ^ However, the run-time environment for a language processor may subdivide the memory dynamically acquired from the operating system, e.g., to implement a stack.
  2. ^ In some operating systems, e.g., OS/360, the free storage may be subdivided in various ways, e.g., subpools in OS/360, below the line, above the line and above the bar in z/OS.
  3. ^ Not to be confused with the unrelated heap data structure.
  4. ^ A simplistic implementation of these two functions can be found in the article "Inside Memory Management".[4]
  5. ^ Except on the Model 67

References

[edit]
  1. ^ a b Detlefs, D.; Dosser, A.; Zorn, B. (June 1994). "Memory allocation costs in large C and C++ programs" (PDF). Software: Practice and Experience. 24 (6): 527–542. CiteSeerX 10.1.1.30.3073. doi:10.1002/spe.4380240602. S2CID 14214110.
  2. ^ a b "Unisys MCP Managing Memory". System Operations Guid. Unisys.
  3. ^ "Main Storage Allocation" (PDF). IBM Operating System/360 Concepts and Facilities (PDF). IBM Systems Reference Library (First ed.). IBM Corporation. 1965. p. 74. Retrieved Apr 3, 2019.
  4. ^ Jonathan Bartlett. "Inside Memory Management". IBM DeveloperWorks.
  5. ^ Silberschatz, Abraham; Galvin, Peter B. (2004). Operating system concepts. Wiley. ISBN 0-471-69466-5.
  6. ^ alloca(3) – Linux Programmer's Manual – Library Functions
  7. ^ "_malloca". Microsoft CRT Documentation. 26 October 2022.
  8. ^ "gnulib/malloca.h". GitHub. Retrieved 24 November 2019.
  9. ^ "glibc/include/alloca.h". Beren Minor's Mirrors. 23 November 2019.
  10. ^ Tanenbaum, Andrew S. (1992). Modern Operating Systems. Englewood Cliffs, N.J.: Prentice-Hall. p. 90. ISBN 0-13-588187-0.
  11. ^ Waychoff, Richard. "Stories About the B5000 and People Who Were There" (PDF). Computer History Museum.
  12. ^ The Descriptor (PDF). Burroughs Corporation. February 1961.
  13. ^ OS360Sup, pp. 82–85.
  14. ^ OS360Sup, pp. 82.
  15. ^ Program Logic: IBM System/360 Operating System MVT Supervisor (PDF). IBM Corporation. May 1973. pp. 107–137. Retrieved Apr 3, 2019.
  16. ^ OSVS1Dig, p. 2.37-2.39.
  17. ^ "Virtual Storage Layout" (PDF). Introduction to OS/VS2 Release 2 (PDF). Systems (first ed.). IBM. March 1973. p. 37. GC28-0661-1. Retrieved July 15, 2024.

Bibliography

[edit]
OS360Sup
OS Release 21 IBM System/360 Operating System Supervisor Services and Macro Instructions (PDF). IBM Systems Reference Library (Eighth ed.). IBM. September 1974. GC28-6646-7.
OSVS1Dig
OS/VS1 Programmer's Reference Digest Release 6 (PDF). Systems (Sixth ed.). IBM. September 15, 1976. GC24-5091-5 with TNLs.
[edit]
脚侧面骨头突出叫什么 取决于你是什么意思 禁锢是什么意思 偶发性房性早搏是什么意思 什么是g点
挂匾是什么意思 什么水果含糖量低 七什么什么什么成语 尿潴留是什么症状 肺气虚吃什么药
努尔哈赤姓什么 dha什么时间段吃最好 肌酐清除率是什么意思 什么是变异性哮喘 卵黄囊是什么意思
皮疹用什么药 狐惑病是什么病 b型血的人是什么性格 mirage轮胎什么牌子 同好是什么意思
益生菌什么牌子好hcv8jop5ns4r.cn 钟是什么生肖jasonfriends.com 15天来一次月经是什么原因hcv7jop7ns0r.cn 6月18是什么日子hcv8jop4ns7r.cn 知了是什么动物hcv9jop5ns0r.cn
剑锋金命五行缺什么hcv8jop1ns0r.cn 飓风什么意思hcv9jop6ns9r.cn 木生什么hcv9jop5ns3r.cn 巨蟹后面的星座是什么hcv8jop3ns8r.cn 梦见抓蝎子是什么意思hcv9jop5ns5r.cn
字义是什么意思hcv8jop5ns3r.cn 什么算熬夜baiqunet.com 佩字五行属什么hcv9jop4ns0r.cn 明心见性是什么意思hcv8jop2ns9r.cn 吃什么可以降血糖hcv8jop1ns0r.cn
静待花开什么意思hcv8jop1ns2r.cn 命门是什么意思hcv8jop0ns9r.cn jeans什么意思hcv8jop1ns8r.cn 什么饮料好喝又健康hcv7jop9ns2r.cn 小狗驱虫用什么药hcv8jop5ns6r.cn
百度