内存池技术讲解(Explanation of memory pool technology)

内存池化

1、池化技术

池化技术是一种常见的提高资源利用率的优化技巧。池化技术先向系统申请程序经常需要使用的核心资源,将这些资源置于“池”中。常见的池化技术包括内存池、线程池、连接池等。

内存池

(1)未使用内存池情况下,频繁通过new/delete、malloc/free 向系统申请/释放内存,必然会导致大量的外碎片出现,增加系统开销,降低程序和操作系统的性能。【内碎片无法避免,只能尽可能地降低】
(2)内存池原理:先向系统申请分配一大块内存作为内存池留作备用,若申请内存,则从池中取出一块;若释放内存,将内存放回内存池,并且尽量与周边的空闲内存块合并。若内存池不够时,则向操作系统申请更大的内存池。

————————

Memory pooling

1. Pool technology

Pooling technology is a common optimization technique to improve resource utilization. Pool technology first applies to the system for the core resources that the program often needs to use, and places these resources in the “pool”. Common pooling technologies include memory pool, thread pool, connection pool, etc.

Memory pool

(1) When the memory pool is not used, < strong > frequently applying for / releasing memory from the system through new / delete and malloc / free will inevitably lead to a large number of external fragments, increase system overhead < / strong >, and reduce the performance of programs and operating systems. [internal debris cannot be avoided and can only be reduced as much as possible]
(2) Principle of memory pool: first apply to the system for allocating a large piece of memory as a memory pool for standby. If you apply for memory, take a piece out of the pool; If the memory is released, put the memory back into the memory pool and merge it with the surrounding free memory blocks as much as possible. If the memory pool is insufficient, request a larger memory pool from the operating system.