#include <fragmentation.h>
Public Member Functions | |
void | AddFragment (size_t inner_size) |
Public Attributes | |
struct { | |
size_t hi = 0 | |
size_t lo = 0 | |
} | sum_of_squares |
Sum-of-squares of the inner sizes of free blocks. | |
size_t | sum = 0 |
Sum of the inner sizes of free blocks. | |
Information that can be used to represent the fragmentation of the block allocator's memory region.
Fragmentation can be measured as 1 minus the normalized root-sum-square of the free block inner sizes, i.e.
1 - (sqrt(sum(U[i]^2)) / sum(U[i])
where U[i]
is the inner size of the i-th free block.
This metric has been described by Adam Sawicki (https://asawicki.info/news_1757_a_metric_for_memory_fragmentation), and used in esp8266/Arduino (https://github.com/esp8266/Arduino/blob/master/cores/esp8266/Esp-frag.cpp), among others.
This struct provides the sum-of-squares and the sum of the inner sizes of free blocks. It is left to the caller to perform the square root and division steps, perhaps on a host, AP, or other device with better floating point support.
The sum-of-squares is stored as a pair of sizes, since it can overflow.