4#include <boost/interprocess/offset_ptr.hpp>
12 template<
typename T,
typename S>
13 class chainbase_node_allocator {
24 if (_freelist ==
nullptr) {
27 list_item* result = &*_freelist;
28 _freelist = _freelist->_next;
32 return pointer{(
T*)_manager->allocate(num*
sizeof(
T))};
37 _freelist =
new (&*
p) list_item{_freelist};
39 _manager->deallocate(&*
p);
46 template<
typename T2,
typename S2>
49 static_assert(
sizeof(
T) >=
sizeof(list_item),
"Too small for free list");
50 static_assert(
sizeof(
T) %
alignof(list_item) == 0,
"Bad alignment for free list");
51 char* result = (
char*)_manager->allocate(
sizeof(
T) * 64);
52 _freelist = bip::offset_ptr<list_item>{(list_item*)result};
53 for(
int i = 0; i < 63; ++i) {
54 char* next = result +
sizeof(
T);
55 new(result) list_item{bip::offset_ptr<list_item>{(list_item*)next}};
58 new(result) list_item{
nullptr};
60 struct list_item { bip::offset_ptr<list_item> _next; };
61 bip::offset_ptr<pinnable_mapped_file::segment_manager> _manager;
62 bip::offset_ptr<list_item> _freelist{};
bip::offset_ptr< T > pointer
bool operator==(const chainbase_node_allocator &other) const
chainbase_node_allocator(segment_manager *manager)
chainbase_node_allocator(const chainbase_node_allocator &other)
void deallocate(const pointer &p, std::size_t num)
bool operator!=(const chainbase_node_allocator &other) const
segment_manager * get_segment_manager() const
pointer allocate(std::size_t num)
chainbase_node_allocator(const chainbase_node_allocator< U, S > &other)
pinnable_mapped_file::segment_manager segment_manager
bip::managed_mapped_file::segment_manager segment_manager
uint32_t next(octet_iterator &it, octet_iterator end)
#define T(meth, val, expected)