MCPcopy Create free account
hub / github.com/caozhiyi/CppNet / ReFill

Method ReFill

base/MemoryPool.cpp:45–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void* CMemoryPool::ReFill(int size, int num) {
46 int nums = num;
47
48 char* chunk = nullptr;
49 try {
50 chunk = (char*)ChunkAlloc(size, nums);
51
52 } catch (const std::exception& e) {
53 LOG_FATAL("malloc memory failed! info : %s", e.what());
54 abort();
55 }
56
57 MemNode* volatile* my_free;
58 MemNode* res, *current, *next;
59 if (1 == nums) {
60 return chunk;
61 }
62
63 res = (MemNode*)chunk;
64
65 my_free = &(_free_list[FreeListIndex(size)]);
66
67 *my_free = next = (MemNode*)(chunk + size);
68 for (int i = 1;; i++) {
69 current = next;
70 next = (MemNode*)((char*)next + size);
71 if (nums - 1 == i) {
72 current->_next = nullptr;
73 break;
74
75 } else {
76 current->_next = next;
77 }
78 }
79 return res;
80}
81
82void* CMemoryPool::ChunkAlloc(int size, int& nums) {
83 char* res;

Callers

nothing calls this directly

Calls 1

whatMethod · 0.80

Tested by

no test coverage detected