28 #ifdef XERUS_REPLACE_ALLOCATOR 35 #include <ext/malloc_allocator.h> 37 namespace xerus {
namespace misc {
39 extern void* (*r_malloc)(size_t);
40 extern void (*r_free)(
void*);
42 using Mallocator = __gnu_cxx::malloc_allocator<void*>;
44 struct AllocatorStorage {
45 static constexpr
const size_t POOL_SIZE = 4*1024*1024;
46 static constexpr
const size_t BUCKET_SIZE = 64;
47 static constexpr
const size_t ALIGNMENT = 64;
48 static constexpr
const size_t NUM_BUCKETS = 64;
49 static constexpr
const size_t SMALLEST_NOT_CACHED_SIZE = BUCKET_SIZE * NUM_BUCKETS - 1;
51 static_assert(BUCKET_SIZE > 1,
"Buckets need to be at least 2 bytes large.");
52 static_assert(BUCKET_SIZE % ALIGNMENT == 0,
"Bucket size needs to be aligned");
53 static_assert(ALIGNMENT <= 256,
"Only alignment up to 256 bytes is supported as only a single byte is used to indicate the offset.");
54 static_assert(NUM_BUCKETS < 255,
"atm only a single byte is used to store bucket size");
56 std::array<std::vector<uint8_t*, Mallocator>, NUM_BUCKETS> buckets;
57 std::vector<std::pair<uint8_t*, uint8_t*>, Mallocator> pools;
62 void create_new_pool();
64 unsigned long allocCount[NUM_BUCKETS];
65 long maxAlloc[NUM_BUCKETS];
66 long currAlloc[NUM_BUCKETS];
69 extern thread_local AllocatorStorage astore;
The main namespace of xerus.