当前位置:网站首页>I Space distributor
I Space distributor
2022-06-25 20:02:00 【Xiaohong_ coding】
List of articles
One . Space allocator
Allocate memory :
When a container needs space to hold elements , Space configurator required ( That is, the distributor ) Allocate memory , When the allocated memory is greater than 128 Bytes , Call the first level configurator , call malloc Allocate memory for it , When the allocated memory is less than 128 Bytes , Call the second level configurator , Check the corresponding free-list Is there a block available on , If any , Use directly , If not, call rfill.
rfill Workflow :
If I found free list After there are no available blocks in , From the memory pool ( adopt chunk_alloc) To get new blocks .
chunk_alloc Workflow :
With end_free - start_free To determine whether there is memory , If there's enough memory , Then get 20 New nodes ( New area block ), When memory pool space is insufficient 20 individual , But satisfy one , Get less 20 Number of nodes , When memory pool No node can be assigned , Call the first level configurator from malloc Recapture a chunk of memory .
At the end of time ,system heap There's not enough space ( Now the computer memory is very large , This rarely happens ), He has out-of-memory Processing mechanism ( similar new_handler Mechanism ), Free up memory elsewhere , Assign in turn , Call again malloc, If you can, you will succeed , If it fails, send out bad_alloc abnormal .
Reclaim memory :
- First, determine the memory size , If memory is greater than 128 Bytes , Call free Reclaiming memory , If memory is less than 128 Bytes , Find out the corresponding free-list Reclaim blocks .
Be careful :malloc and free from os From there
First level configurator :
- allocate() Use it directly malloc(),deallocate() Use it directly free().
- simulation c ++ Of set_new_handler() To handle out of memory conditions .
Second level configurator :
maintain 16 A free list (free list).
- be responsible for 16 Configuration capability of small blocks .
- Memory pool (memory) With malloc( ) From configuration . If there is not enough memory , Call the first level configurator ( There is memory processing ).
If the demand block is greater than 128bytes, Then call the first level configurator .
If the demand block is greater than 128bytes, Then call the first level configurator .
边栏推荐
猜你喜欢
2.3 partial sum of square and reciprocal sequences
Arduino read temperature
SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
Can GoogleSEO only do content without external chain? (e6zzseo)
Vulnhub range the planes: mercury
Redis core article: the secret that can only be broken quickly
wooyun-2014-065513
Pta--7-20 exchange minimum and maximum (15 points)
Profile path and name
Process of vacuum and vacuum full
随机推荐
New features of php7
Can GoogleSEO only do content without external chain? (e6zzseo)
Please do not call Page constructor in files
Randomly generate 100 non repeating numbers between 1 and 150 and put them in the array
PAT B1051
Process of vacuum and vacuum full
Print 1 cute every 100 milliseconds ~ with a running lantern effect
Web container basic configuration
2.15(Multiple of 3 Or 5)
Single chip microcomputer line selection method to store impression (address range) method + Example
PAT B1066
Two types of attribute injection methods
PAT B1061
2.14(Knight Moves)
在打新债开户证券安全吗?低佣金靠谱吗
String since I can perform performance tuning, I can call an expert directly
Huawei in application review test requirements
在打新债开户证券安全吗
PHP Chinese regular
Some pictures of real machine preview development and debugging are not shown