官术网_书友最值得收藏!

Memory allocation

Memory is another resource that an application must request using a system call. Most applications are given global and stack memory resources when the application is first executed, along with a small heap of memory that the application can use when calls to functions such as malloc() and free() are made.

If the application only uses the memory that it is initially given in this heap, no extra memory needs to be requested by the application. If, however, heap memory runs out, the application's malloc() or free() engine will have to ask the operating system (via a system call) for more memory.

To do this, the operating system will extend the end of the application by adding more physical memory to the application. The malloc() or free() engine is then able to make use of this additional memory, until more is needed. 

On systems with limited RAM, when a request for additional memory is made, the operating system has to take memory from other applications that aren't currently executing. It does this by swapping these applications to disk, an operation that is expensive to perform.

For this reason, on resource-constrained systems, calls to malloc() or free() should not be made in time-critical code, as the time it takes to execute these functions can vary greatly.

We will go into further detail on memory management in Chapter 7, A Comprehensive Look at Memory Management

主站蜘蛛池模板: 锡林浩特市| 文山县| 新安县| 广灵县| 富阳市| 平果县| 兴安县| 福泉市| 衡阳县| 岳池县| 平南县| 瑞金市| 佳木斯市| 磴口县| 麻城市| 温州市| 苏尼特右旗| 临夏县| 琼海市| 上饶县| 白城市| 荃湾区| 桓仁| 区。| 海南省| 仪征市| 大关县| 建昌县| 泸水县| 延安市| 安溪县| 景泰县| 大悟县| 贵南县| 稷山县| 扬州市| 灵璧县| 浠水县| 仁寿县| 达日县| 盖州市|