It seems that the memory pool is a deep topic. Whenever you want to try it, you feel that you have not accumulated enough. Today, we have finally accumulated a memory pool, and there will be time. I have read the alloc in STL, that is, the design idea and Implementation of the Space configurator. The ace block is different from the memory pool.
Today, a memory pool is available, which is implemented according to the idea of the STL space empty configurator, that is, the memory block is managed by the vertical and horizontal linked list. Horizontal linked lists manage memory blocks of different sizes, and vertical linked lists manage memory blocks of the same size. To avoid Memory waste, nodes that manage memory blocks use Union, externally, It is the address of memory that can be used, and internally it is directed to the next available memory block.
The advantages of using the memory pool are obvious:
1. Avoid frequent requests from the system to release memory fragments;
2. Avoid applying to the system every time the memory is used (new or malloc, new or malloc each time, the efficiency is low );
3. Avoid Memory leakage (you can manage the application and release of memory by yourself, and you can use the idea of resource management objects)
Disadvantages:
1. The memory pool implemented by the author only applies to the system and does not return it to the system. That is to say, the memory usage will be stable when it reaches a certain stage, even ifProgramAt this time, the memory is not actually used, but it also occupies a large amount of memory;
Mempool download