Memory pool (thread pool) and Malloc/free

Source: Internet
Author: User

What is a memory pool

(Memory Pool) is a way of allocating memories.

A memory pool is a request to allocate a certain number of memory blocks of equal size (in general) to be reserved before actually using memory. When there is a new memory requirement, a portion of the memory block is separated from the memory pool, and if the memory block is not enough, then continue to request new memory. One notable advantage of this is that the efficiency of memory allocation is improved.

There are a number of local memory allocations in the kernel that do not allow failures. As a way to ensure allocation in these cases, the kernel developer creates an abstraction known as a memory pool (or "Mempool"). A memory pool is really just a kind of fallback cache, and it tries to keep a list of free memory to use in an emergency.

Disadvantages of Malloc/free

Often we are used to request allocation of memory directly using APIs such as new and malloc, which are usually thread-safe, but the disadvantage of this is that due to the variable size of the requested memory block, a large amount of memory fragmentation is caused when used frequently and thus degrades performance (malloc/ The free function causes the user to switch between the state and the kernel, lock and unlock, and so on.

Incidentally, Mark. Good article: http://m.blog.csdn.net/blog/chhuach2005/23863625

Memory pool (thread pool) and Malloc/free

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.