In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, Xiaobian will bring you about how to understand Netty memory management PoolChunk. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Years ago, the move from manual management of C memory to automatic GC in Java was a huge step forward in history. Years later, however, netty's memory implementation curved back to manual management mode, confirming marx's philosophy that society always spirals forward and that there is no eternal best. Indeed, in terms of memory management, GC brings value to programmers is self-evident, not only greatly reducing the burden on programmers, but also greatly reducing the Crash trouble caused by memory management, but there are also many cases where manual memory management may be more appropriate.
Prepare a few paragraphs for an in-depth analysis of Netty's memory management.
PoolChunk
In order to be able to manipulate memory easily, it is necessary to ensure that each memory allocation is continuous. The memory allocation and recycling management at the bottom of Netty is mainly implemented by PoolChunk, which maintains a balanced binary tree memoryMap internally, and the memory managed by all child nodes also belongs to its parent node.
poolChunk consists of 2048 pages by default, the default size of a page is 8k, and the values of nodes in the graph are subscripts in the array memoryMap.
If you need to allocate 8k memory, you only need to find the first available node at the 11th layer.
If you need to allocate 16k memory, you only need to find the first available node at the 10th layer.
3. If node 1024 has a child node 2048 that has been allocated, then the node cannot be allocated. For example, if 16k memory needs to be allocated, node 2048 has been allocated at this time, and node 2049 has not been allocated, node 1024 cannot be allocated directly, because the node currently only has 8k memory left.
poolChunk internally guarantees that the memory size allocated each time is 8K *(2n). In order to allocate a node of size chunkSize/(2k), it is necessary to match nodes from the left at a depth of k. So how to allocate the specified memory quickly?
memoryMap initialization:
memoryMap = new byte[maxSubpageAllocs
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.