2023-01-21 14:34:29 +01:00
|
|
|
#include "SimpleAllocator.h"
|
2020-02-23 10:49:37 -08:00
|
|
|
#include "assert.h"
|
2022-12-30 10:56:57 -06:00
|
|
|
#include "configuration.h"
|
2020-02-23 13:20:46 -08:00
|
|
|
|
2023-01-21 14:34:29 +01:00
|
|
|
SimpleAllocator::SimpleAllocator()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
}
|
2020-02-23 10:49:37 -08:00
|
|
|
|
|
|
|
|
void *SimpleAllocator::alloc(size_t size)
|
|
|
|
|
{
|
|
|
|
|
assert(nextFree + size <= sizeof(bytes));
|
|
|
|
|
void *res = &bytes[nextFree];
|
|
|
|
|
nextFree += size;
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Total simple allocs %u", nextFree);
|
2020-02-23 10:49:37 -08:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 14:34:29 +01:00
|
|
|
void SimpleAllocator::reset()
|
|
|
|
|
{
|
|
|
|
|
nextFree = 0;
|
|
|
|
|
}
|
2020-02-23 10:49:37 -08:00
|
|
|
|
|
|
|
|
void *operator new(size_t size, SimpleAllocator &p)
|
|
|
|
|
{
|
|
|
|
|
return p.alloc(size);
|
|
|
|
|
}
|