MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / allocate

Method allocate

TheForceEngine/TFE_System/memoryPool.cpp:27–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void* MemoryPool::allocate(size_t size)
28{
29 if (size == 0) { return nullptr; }
30
31 if (m_ptr + size > m_poolSize)
32 {
33 TFE_System::logWrite(LOG_ERROR, "MemoryPool", "Allocate of size %u bytes failed for memory pool \"%s\"", size, m_name.c_str());
34 return nullptr;
35 }
36 else if (m_ptr + size >= m_waterMark && m_waterMark > 0u)
37 {
38 TFE_System::logWrite(LOG_WARNING, "MemoryPool", "Pool \"%s\" is at %0.2f%% capacity.", m_name.c_str(), 100.0f * f32(m_ptr + size) / f32(m_poolSize));
39 // Change the watermark to be closer to full to avoid spamming the log.
40 m_waterMark = (m_waterMark + m_poolSize) >> 1;
41 }
42
43 u8* memory = m_memory.data() + m_ptr;
44 m_ptr += size;
45
46 return memory;
47}
48
49void* MemoryPool::reallocate(void* ptr, size_t oldSize, size_t newSize)
50{

Callers 7

cJSON_strdupFunction · 0.45
cJSON_New_ItemFunction · 0.45
ensureFunction · 0.45
parse_stringFunction · 0.45
printFunction · 0.45
cJSON_PrintBufferedFunction · 0.45
cJSON_mallocFunction · 0.45

Calls 3

logWriteFunction · 0.85
c_strMethod · 0.80
dataMethod · 0.80

Tested by

no test coverage detected