Memory management (1) -- dynamic partition allocation strategy

1. First match: allocate n bytes, use the first free area with free space larger than n
Principle: The list of free partitions is sorted according to the address order; During the allocation process, search for the first suitable partition; When releasing a partition, check whether it can be merged with an adjacent free partition,
Pros: Simple; large free partitions in high address space
Cons: External fragmentation; allocating large blocks is slower
2. Best match : When allocating n bytes, find and use the smallest free partition not less than n
Principle: The list of free partitions is sorted by size; when allocating, find a suitable partition; when releasing, find and merge adjacent free partitions;
Advantages: Avoid large free partitions from being split; can reduce the size of external fragments;
Disadvantages: external fragmentation; slower to release partitions; prone to many useless small fragments
3. Worst match ; when allocating n bytes, find and use the largest free partition not less than n
Principle: The list of free partitions is sorted in descending order; when allocating, select the largest partition; when releasing, check whether it can be merged with adjacent free partitions, carry out possible merges, and adjust the order of the list of free partitions;
Advantages: Allocation works best when there are many medium-sized allocations; avoids too many small fragments;
Disadvantages: slow release of partitions; external fragmentation; easy to destroy large free partitions, so it is difficult to assign large partitions later

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325940913&siteId=291194637