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

Method alloc_with_defrag

imperative/src/impl/blob_manager_impl.cpp:29–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29void BlobManagerImpl::alloc_with_defrag(OwnedBlob* blob, size_t size) {
30 if (m_custom_allocator) {
31 blob->m_storage = m_custom_allocator(blob->m_comp_node, size);
32 return;
33 }
34 // try alloc
35 // if fail, try defrag, alloc again
36 if (!try_alloc_direct(blob, size)) {
37 mgb_log_warn("memory allocation failed for blob; try defragmenting");
38 defrag(blob->m_comp_node);
39 alloc_direct(blob, size);
40 }
41}
42
43void BlobManagerImpl::alloc_direct(OwnedBlob* blob, size_t size) {
44 mgb_assert(blob->m_comp_node.valid());

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected