27 uint64_t
alloc(
const uint64_t & alloc_size)
31 if (m_used_ranges.empty() && m_capacity >= alloc_size)
33 m_used_ranges[0] = alloc_size;
37 for (
auto it = m_used_ranges.begin(); it != m_used_ranges.end(); ++it)
39 if (it->first - address >= alloc_size)
41 m_used_ranges[address] = alloc_size;
44 address = it->first + it->second;
47 if (m_capacity - address >= alloc_size)
49 m_used_ranges[address] = alloc_size;
56 void free(
const uint64_t & address)
58 m_used_ranges.erase(address);
63 std::map<uint64_t, uint64_t> m_used_ranges;
Definition: MemoryRange.hpp:9
~MemoryRange()
Definition: MemoryRange.hpp:13
MemoryRange(const uint64_t &capacity=0)
Definition: MemoryRange.hpp:15
void add(const uint64_t &capacity)
Definition: MemoryRange.hpp:22
uint64_t alloc(const uint64_t &alloc_size)
Definition: MemoryRange.hpp:27
uint64_t capacity()
Definition: MemoryRange.hpp:20
void free(const uint64_t &address)
Definition: MemoryRange.hpp:56