[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a ...">

当前位置:网站首页>Memory pool principle I (based on the whole block)

Memory pool principle I (based on the whole block)

2022-06-10 18:05:00 QQ851301776

Created by QQ:851301776, mailbox :[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a little progress every day !

Personal motto :
1. No one was born , As long as it is thick, it will happen .
2. You can have a low degree , You can skip school , But you have to learn

One 、 Memory pool design ideas

1. Memory pool solves the problem (malloc/free)

(1) Not conducive to memory management

(2) Memory fragmentation is severe

(3) Programs are prone to memory leaks , Eventually a memory overflow occurs

2. Memory pool design practices (4K)

(1) Partner algorithm

         Distribute : hold 4K, according to 2 Of n Power method , from 0 Begin to assign to :1/2/4/8/16/32/64/128/256/512/1K/2K These pieces , Core thinking : Turn the whole block into pieces

Use : Such as the need to 129 Bytes : It will 256 This block is split again into :128/64/32/16/8/4/2/1,

         Merge : Combine two adjacent pieces of the same size , With the next piece . The first condition is that two blocks are adjacent , The second condition is that the two pieces must be the same size .

         Release : Turn small pieces into big ones , Unified release

(2)slab

         No explanation here , You can see nginx Use slab Memory pool part of (slab The core is to : For example, a 4K Page of , All become 4/8/16( Numbers are just examples ), This small piece )

原网站

版权声明
本文为[QQ851301776]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101715249180.html