Update memory.cpp

This commit is contained in:
blueloveTH 2024-03-22 12:31:10 +08:00
parent 736df8ad31
commit fbd825951c

View File

@ -238,14 +238,11 @@ struct MemoryPool{
std::string info(){ std::string info(){
int n_used_arenas = _arenas.size(); int n_used_arenas = _arenas.size();
int n_total_arenas = n_used_arenas + _empty_arenas.size(); int n_total_arenas = n_used_arenas + _empty_arenas.size();
int n_used_blocks = 0;
int n_total_blocks = n_total_arenas * __MaxBlocks;
size_t allocated_size = 0; size_t allocated_size = 0;
size_t total_size = 0; size_t total_size = 0;
_arenas.apply([&](Arena* arena){ _arenas.apply([&](Arena* arena){
allocated_size += arena->allocated_size(); allocated_size += arena->allocated_size();
total_size += __BlockSize * __MaxBlocks; total_size += __BlockSize * __MaxBlocks;
n_used_blocks += __MaxBlocks - arena->_free_list_size;
}); });
_empty_arenas.apply([&](Arena* arena){ _empty_arenas.apply([&](Arena* arena){
total_size += __BlockSize * __MaxBlocks; total_size += __BlockSize * __MaxBlocks;
@ -254,14 +251,12 @@ struct MemoryPool{
snprintf( snprintf(
buffer, buffer,
sizeof(buffer), sizeof(buffer),
"MemoryPool<%d>: %.2f/%.2f MB - %d/%d arenas - %d/%d blocks", "pool%d: %.2f/%.2f MB - %d/%d arenas",
__BlockSize, __BlockSize,
(float)allocated_size / (1024*1024), (float)allocated_size / (1024*1024),
(float)total_size / (1024*1024), (float)total_size / (1024*1024),
n_used_arenas, n_used_arenas,
n_total_arenas, n_total_arenas
n_used_blocks,
n_total_blocks
); );
return buffer; return buffer;
} }