Malloc implementation principle, malloc implementation

Source: Internet
Author: User

Malloc implementation principle, malloc implementation
How is malloc implemented? The answer is: it can be implemented based on the partner system (the partner system has been mentioned in the previous article), or it can be implemented based on the linked list. Zookeeper

  • It has a so-called connection to available memory blocks into a long listIdle linked list
  • When calling the malloc function, it searches for a memory block that is large enough to meet user requests along the connection table. The memory block is then split into two parts (the size of one part is equal to the size of the user request, and the size of the other part is the remaining bytes ). Next, pass the memory allocated to the user, and return the remaining (if any) to the connection table.
  • When the free function is called, it connects the memory block released by the user to the idle chain.

This involves a problem: the idle chain will be cut into many small memory segments. If the user requests a large memory segment, there may be no fragments on the idle link that meet user requirements.

So how can we solve this problem?

Solve external fragments: malloc function request latency, and start to rummaging through the idle chain to check and sort out memory fragments,Merge adjacent small idle blocks into larger memory blocks.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.