Process's address space and heap
2016-01-27 12:03
295 查看
Typically, in each process, the virtual memory available to that process is called its address space. Each process's address space is typically organized in 6 sections that are illustrated in the next picture: environment section - used to store environment variables andcommand line arguments; the stack, used to store memory for function arguments, return values, and automatic variables; the heap (free store) used for dynamic allocation, two data sections (for initialized and uninitialized static and global variables) and a text section where the actual code is kept.
Heap is the area of memory in which objects with dynamic extent are allocated. The lifetime of object is greater than the lifetime of the procedure that creates it. This object is said to have dynamic extent.
When new is invoked, it starts looking for a free memory block that fits the size for your request. Supposing that such a block of memory is found, it is marked as reserved and a pointer to that location is returned. There are several algorithms to accomplish this because a compromise has to be made between scanning the whole memory for finding the smallest free block bigger than the size of your object, or returning the first one where the memory needed fits. In order to improve the speed of getting a block of memory, the free and reserved areas of memory are maintained in a data structure similar to binary trees called a heap. The various algorithms for finding free memory are beyond the scope of this article and you can find a thorough discussion about them in D. Knuth's monographThe Art of Computer Programming -- Vol.1, Fundamental Algorithms). This overhead combined with the risk for memory leaks makes the use of automatic memory (allocated on the stack) preferred whenever possible and the allocation is not large.
参考文献:
http://www.cprogramming.com/tutorial/virtual_memory_and_heaps.html
Heap is the area of memory in which objects with dynamic extent are allocated. The lifetime of object is greater than the lifetime of the procedure that creates it. This object is said to have dynamic extent.
The Heap
To understand why the dynamic memory allocation is time consuming let's take a closer look at what is actually happening. The memory area where new gets its blocks of memory for allocation (usually called free store or heap) is illustrated in the following picture:When new is invoked, it starts looking for a free memory block that fits the size for your request. Supposing that such a block of memory is found, it is marked as reserved and a pointer to that location is returned. There are several algorithms to accomplish this because a compromise has to be made between scanning the whole memory for finding the smallest free block bigger than the size of your object, or returning the first one where the memory needed fits. In order to improve the speed of getting a block of memory, the free and reserved areas of memory are maintained in a data structure similar to binary trees called a heap. The various algorithms for finding free memory are beyond the scope of this article and you can find a thorough discussion about them in D. Knuth's monographThe Art of Computer Programming -- Vol.1, Fundamental Algorithms). This overhead combined with the risk for memory leaks makes the use of automatic memory (allocated on the stack) preferred whenever possible and the allocation is not large.
参考文献:
http://www.cprogramming.com/tutorial/virtual_memory_and_heaps.html
相关文章推荐
- nefu 115 斐波那契的整除
- cvpr2015文章整理
- 多应用共享cookie引发的问题
- C#版机房重构登录(不完整版)
- 网站扩展实例:1亿用户、50亿pv的Tagged架构进化史
- 用grunt搭建自动化的web前端开发环境-完整教程
- Linux中与DNS相关的内容
- HDU 1717
- 小微助手是真的吗?小微助手下载
- java数学函数Math类中常用的方法
- Android Design Support Library介绍之:环境搭建
- FEC CProfile 使用
- iOS统计数组相同元素的个数(使用数组筛选计算)
- 接口文档示例
- 国外支付(Paypal,Cybersource)
- koa框架异步返回值的操作(co,koa-compose)
- 代码的坏味道
- 实现多层抽屉菜单,点击其中一项会动画打开该抽屉--第三方开源--MultiCardMenu
- Python图像灰度变换及图像数组操作
- git 生成SSH KEY