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

Method alloc

src/core/impl/utils/mempool.cpp:19–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void* MemPoolStorage::alloc(size_t elem_size) {
20 constexpr size_t MAX_BUF_SIZE = 32 * 1024; // max 32 KiB per buf
21 if (!m_free.empty()) {
22 auto ptr = m_free.back();
23 m_free.pop_back();
24 return ptr;
25 }
26 if (m_cur_buf_pos >= m_cur_buf_size_bytes) {
27 auto buf_size = m_cur_buf_size_bytes;
28 if (!buf_size) {
29 buf_size = elem_size * 2;
30 }
31 buf_size = std::min(buf_size * 2, 2048 * elem_size);
32 if (buf_size > MAX_BUF_SIZE) {
33 buf_size = std::max<size_t>(
34 MAX_BUF_SIZE - MAX_BUF_SIZE % elem_size, 16 * elem_size);
35 }
36 m_buf.emplace_back(new uint8_t[buf_size]);
37 m_cur_buf_pos = 0;
38 m_cur_buf_size_bytes = buf_size;
39 }
40 auto ptr = m_buf.back().get() + m_cur_buf_pos;
41 m_cur_buf_pos += elem_size;
42 return ptr;
43}
44
45void MemPoolStorage::free(void* ptr) {
46 if (!m_disable_freelist)

Callers 11

check_versionMethod · 0.45
eager_eval.cppFile · 0.45
addMethod · 0.45
register_shape_inferMethod · 0.45
register_value_inferMethod · 0.45
init_topo_orderMethod · 0.45

Calls 6

backMethod · 0.80
emplace_backMethod · 0.80
minFunction · 0.50
emptyMethod · 0.45
pop_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected