MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / add

Method add

src/core/test/mem_alloc.cpp:106–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104 : m_root_allocator(std::move(root_alloc)) {}
105
106 void add(void* addr_, size_t size) {
107 ASSERT_NE(nullptr, addr_);
108 mgb_assert((char*)addr_ + size <= m_root_allocator->get_chunk_end(addr_));
109 auto addr = reinterpret_cast<size_t>(addr_);
110 MGB_LOCK_GUARD(m_mtx);
111 auto rst = m_addr2size.insert({addr, size});
112 mgb_assert(rst.second, "duplicated address: %p", addr_);
113 auto iter = rst.first;
114 if (mgb_likely(iter != m_addr2size.begin())) {
115 auto iprev = iter;
116 --iprev;
117 mgb_assert(iprev->first + iprev->second <= addr);
118 }
119 auto inext = iter;
120 ++inext;
121 if (mgb_likely(inext != m_addr2size.end())) {
122 mgb_assert(addr + size <= inext->first);
123 }
124
125 m_cur_usage += size;
126 m_peak_usage = std::max(m_peak_usage, m_cur_usage);
127 }
128
129 void remove(void* addr) {
130 MGB_LOCK_GUARD(m_mtx);

Callers 4

TESTFunction · 0.45
TEST_PFunction · 0.45
TESTFunction · 0.45
get_opr_typesFunction · 0.45

Calls 5

maxFunction · 0.85
get_chunk_endMethod · 0.80
insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected