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

Method alloc

src/core/test/mem_alloc.cpp:44–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 }
43
44 void* alloc(size_t size) override {
45 MGB_LOCK_GUARD(m_mtx);
46 if (mgb_unlikely(m_cur_usage + size > m_tot_size)) {
47 m_ever_failed = true;
48 return nullptr;
49 }
50 ++m_nr_alloc;
51 auto addr = reinterpret_cast<void*>(m_next_addr);
52 m_next_addr += size;
53 m_cur_usage += size;
54 m_peak_usage = std::max(m_peak_usage, m_cur_usage);
55 m_addr2size[addr] = size;
56 return addr;
57 }
58
59 void free(void* ptr) override {
60 MGB_LOCK_GUARD(m_mtx);

Callers 2

TESTFunction · 0.45
TESTFunction · 0.45

Calls 1

maxFunction · 0.85

Tested by

no test coverage detected