The memory pool is a technology used to allocate a large number of small memory blocks of the same size, which can greatly accelerate the memory allocation/release process.
Mempool technology memory allocation, release speed is very fast, reached the O (1) level.
Disadvantages:
1). Only Memory of specific bytes can be allocated. That is to say, mempool is not a general memory manager.
2). mempool technology may cause memory usage to only increase and decrease.
The basic implementation is as follows:
The pointer variable memblockheader concatenates all applied memory blocks into a linked list so that all applied memory blocks can be released.
The freenodeheader variable concatenates all free Memory nodes (freenode) into a linked list.
The memory block size is generally fixed to memblocksize bytes (excluding pointers used to create a linked list ).
Memory blocks are divided into Multiple Memory nodes at the beginning of application.The size of each node is itemsize (the size of a small object), measured in memblocksize/itemsize.
Memblock and freenode are as follows:
The application process is as follows:
The memory application process can be divided into two situations:
1). freenodelist is not empty. The allocation process is only the process of extracting the next node from the list of free Memory nodes.
2). Otherwise, a new memory block is required. You need to apply again and cut the applied memblock into multiple nodes.
The release process is as follows:
The release process only mounts the node to be released to the beginning of the free memory linked list (freenodelist.
The STL space configurator uses the memory pool technology to allocate less than bytes.
The parameter uses a free linked list of multi-level block sizes, and the free node parameters are designed using the Union structure to reduce additional overhead.
See http://www.cnblogs.com/dwdxdy/archive/2012/06/05/2537208.html for details
References: http://cplusplus.wikidot.com/cn:dive-into-memory-pool