11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
21PROMEKI_NAMESPACE_BEGIN
42 size_t numAllocatedBlocks;
43 size_t largestFreeBlock;
51 bool allocated =
false;
57 bool operator<(
const Block &other)
const {
return address < other.address; }
64 uintptr_t alignedAddress(
size_t align)
const {
65 uintptr_t _align = align - 1;
66 return (address + _align) & ~(_align);
73 uintptr_t alignedAddress()
const {
return alignedAddress(alignment); }
80 size_t padding(
size_t align)
const {
81 return align > 1 ? alignedAddress(align) - address : 0;
88 size_t padding()
const {
return padding(alignment); }
95 bool follows(
const Block &block)
const {
96 return static_cast<uintptr_t
>(block.address) + block.size ==
97 static_cast<uintptr_t
>(address);
106 static bool isValidAlignment(
size_t val) {
return (val > 0) && !(val & (val - 1)); }
108 using BlockSet = ::promeki::Set<Block>;
109 using BlockMap = ::promeki::Map<uintptr_t, Block>;
119 void addRegion(uintptr_t startingAddress,
size_t size);
126 void addRegion(
void *startingAddress,
size_t size) {
127 addRegion(
reinterpret_cast<uintptr_t
>(startingAddress), size);
132 const String &name()
const {
return _name; }
138 void setName(
const String &val) {
153 BlockSet memoryMap()
const;
164 void *allocate(
size_t size,
size_t alignment = 1);
173 void free(
void *ptr);
177 mutable Mutex _mutex;
178 BlockSet _freeBlocks;
179 BlockMap _allocatedBlocks;