代码拉取完成,页面将自动刷新
同步操作将从 启明南/YuGC-Study 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <iostream>
#include "include/memory_pool.h"
//运行打印乱码,对照:https://blog.csdn.net/weixin_43892298/article/details/105732781
//每个文件都要右窗口右下角选择 “GBK” -> "convert"
int main() {
// 创建一个内存池
MemoryPool *mem_pool = new MemoryPool();
// 创建一个chunk
MemoryChunk *mem_chunk = mem_pool->new_chunk(78);
// 分配内存
mem_chunk->malloc(8);
mem_chunk->malloc(16);
mem_chunk->malloc(32);
mem_chunk->malloc(24);
/* 输出:
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:216->print_used_table):[打印used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=7, cell_end=10, cell_size=3
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=3, cell_end=7, cell_size=4
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=1, cell_end=3, cell_size=2
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=0, cell_end=1, cell_size=1
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:224->print_used_table):[打印used_table]结束
*/
// 模拟Chunk的内存分光了
// mem_chunk->malloc(8);
// [Error] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:162->malloc):没有满足条件的Chunk,无法分成内存,程序退出
mem_pool->print_chunks();
delete mem_pool;
return 0;
}
/* Output:
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:203->print_available_table):[打印available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:208->print_available_table): cell_start=0, cell_end=10, cell_size=10
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:211->print_available_table):[打印available_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:108->to_string):[Cell信息]找到了满足条件的Cell:start=0, end=10, size=10
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:50->real_malloc):[真正分配内存]Data起始地址=EF1CB0, cell_start=0, ret=64FC68
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:203->print_available_table):[打印available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:208->print_available_table): cell_start=1, cell_end=10, cell_size=9
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:211->print_available_table):[打印available_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:216->print_used_table):[打印used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=0, cell_end=1, cell_size=1
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:224->print_used_table):[打印used_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:108->to_string):[Cell信息]找到了满足条件的Cell:start=1, end=10, size=9
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:50->real_malloc):[真正分配内存]Data起始地址=EF1CB0, cell_start=1, ret=64FCA8
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:203->print_available_table):[打印available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:208->print_available_table): cell_start=3, cell_end=10, cell_size=7
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:211->print_available_table):[打印available_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:216->print_used_table):[打印used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=1, cell_end=3, cell_size=2
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=0, cell_end=1, cell_size=1
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:224->print_used_table):[打印used_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:108->to_string):[Cell信息]找到了满足条件的Cell:start=3, end=10, size=7
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:50->real_malloc):[真正分配内存]Data起始地址=EF1CB0, cell_start=3, ret=64FD28
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:203->print_available_table):[打印available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:208->print_available_table): cell_start=7, cell_end=10, cell_size=3
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:211->print_available_table):[打印available_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:216->print_used_table):[打印used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=3, cell_end=7, cell_size=4
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=1, cell_end=3, cell_size=2
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=0, cell_end=1, cell_size=1
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:224->print_used_table):[打印used_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:108->to_string):[Cell信息]找到了满足条件的Cell:start=7, end=10, size=3
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:50->real_malloc):[真正分配内存]Data起始地址=EF1CB0, cell_start=7, ret=64FE28
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:174->free_available_table):[释放available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:15->~MemoryCell):[调用析构函数~MemoryCell]释放资源
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:203->print_available_table):[打印available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:211->print_available_table):[打印available_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:216->print_used_table):[打印used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=7, cell_end=10, cell_size=3
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=3, cell_end=7, cell_size=4
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=1, cell_end=3, cell_size=2
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:221->print_used_table): cell_start=0, cell_end=1, cell_size=1
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:224->print_used_table):[打印used_table]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:28->print_chunks):[打印未释放的内存]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:35->print_chunks): [未释放的内存]申请位置:( G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:18 ), 内存大小:80 字节
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:38->print_chunks):[打印未释放的内存]结束
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:10->~MemoryPool):[调用析构函数]~MemoryPool
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:30->~MemoryChunk):[调用析构函数~MemoryChunk]释放资源
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:33->~MemoryChunk): 释放资源, 申请内存位置( G:\OtherWorkSpace\YuGC-Study\src\memory_pool.cpp:18 ),内存大小:80 字节
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:174->free_available_table):[释放available_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_chunk.cpp:186->free_used_table):[释放used_table]开始
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:15->~MemoryCell):[调用析构函数~MemoryCell]释放资源
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:15->~MemoryCell):[调用析构函数~MemoryCell]释放资源
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:15->~MemoryCell):[调用析构函数~MemoryCell]释放资源
[Info] (G:\OtherWorkSpace\YuGC-Study\src\memory_cell.cpp:15->~MemoryCell):[调用析构函数~MemoryCell]释放资源
*///~
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。