30 inline std::size_t alignment_size(std::size_t
size)
33 return (
size < one)? one: (
size <
sizeof(std::max_align_t))?
40 m_data{
static_cast<decltype(m_data)
>(
Alloc(config.preallocation_size))},
41 m_entries{
static_cast<AllocationRecord*
>(
Alloc(config.allocation_records *
sizeof(AllocationRecord)))},
42 m_size{config.preallocation_size},
43 m_max_entries{config.allocation_records}
51 assert(m_entryCount == 0);
58 assert(m_index <= m_size);
60 if (m_entryCount < m_max_entries)
62 auto entry = m_entries + m_entryCount;
64 const auto available = m_size - m_index;
65 if (
size > (available /
sizeof(std::max_align_t)) *
sizeof(std::max_align_t))
67 entry->data =
static_cast<decltype(entry-
>data)>(
Alloc(
size));
68 entry->usedMalloc =
true;
72 auto ptr =
static_cast<void*
>(m_data + m_index);
73 auto space = available;
74 entry->data = std::align(alignment_size(
size),
size, ptr, space);
75 entry->usedMalloc =
false;
76 size += (available - space);
82 m_maxAllocation = std::max(m_maxAllocation, m_allocation);
94 assert(m_entryCount > 0);
95 const auto entry = m_entries + m_entryCount - 1;
96 assert(p == entry->data);
97 if (entry->usedMalloc)
103 assert(m_index >= entry->size);
104 m_index -= entry->size;
106 assert(m_allocation >= entry->size);
107 m_allocation -= entry->size;