In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Advanced programming in UNIX Environment
In most operating systems, memory allocation is handled by the following two simple functions:
Void * malloc (long numbytes): this function allocates numbytes-sized memory and returns a pointer to the first byte.
Void free (void * firstbyte): given a pointer returned by the previous malloc, this function returns the allocated space to the process's "free space".
Heavy use of malloc and free results in memory fragmentation, so what is the principle of this fragmentation?
If the mechanism is caused by the size of the requested memory space (too small), then how large the area of the application can minimize memory fragmentation? (avoidance here is not an absolute avoidance, but a probability.)
Memory fragmentation is generally due to the fact that the free contiguous space is smaller than the space to be applied for, so that these small blocks of memory cannot be utilized.
The way to generate memory fragmentation is simple, for example:
Suppose you have a block of 100 units of contiguous free memory with a range of 099. If you apply for a piece of memory, such as 10 units, then the applied memory block is in the range of 0,9. At this point, you continue to apply for a piece of memory, say 5 units, and the second block of memory should be between 10 and 14.
If you release the first block of memory, then apply for a block of memory greater than 10 units, say 20 units. Because the memory blocks that have just been released cannot meet the new requests, only 20 units of memory blocks can be allocated starting from 15.
Now the state of the entire memory space is 0: 9 idle, 10: 14 occupied, 15: 24 occupied, and 25: 99 idle. Among them, 0# 9 is a memory fragment. If 10-14 is occupied all the time, and the space applied for later is more than 10 units, then 0-14 will never be used, resulting in a waste of memory.
If the memory size of each application is smaller than the size of the previous release of the village, then the application will always be successful.
Some people like to write their own memory management module, the program begins to apply for a large piece of memory, and then later apply for memory in this large memory, with certain skills to reduce the problem of memory fragmentation.
Generally per page, 4k
Malloc and operator new all have their own allocation strategies. As long as you don't use the system API, but use the library, you generally don't have to think about it yourself.
In general, if the memory you apply for is relatively large and regular (for example, you only apply for 16k and 4k memory), it will not be a problem. But in this case, you have to add a level to deal with the large memory.
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.