1#ifndef NNGN_UTILS_ALLOC_TAGGED_H
2#define NNGN_UTILS_ALLOC_TAGGED_H
18 typename T::value_type;
20 typename T::block_type;
41 typename A = std::allocator<typename D::block_type::value_type>>
50 typename std::allocator_traits<A>::template rebind_alloc<char>;
56 typename std::allocator_traits<allocator>
57 ::template rebind_alloc<U>>;
63 template<tagging_descriptor D1,
typename A1>
75 requires(detail::has_typed_alloc<
allocator, I>);
77 requires(detail::has_realloc<A>);
83 static auto alloc_size(std::size_t
n) {
return block_type::alloc_size(
n); }
87template<tagging_descriptor D,
typename A>
89 auto b = block_type::from_storage_ptr(p);
90 new (b.header())
typename block_type::header_type;
94template<tagging_descriptor D,
typename A>
99template<tagging_descriptor D,
typename A>
103 this->alloc = rhs.
alloc;
107template<tagging_descriptor D,
typename A>
108template<tagging_descriptor D1,
typename A1>
110 : alloc{rhs.get_allocator()} {}
112template<tagging_descriptor D,
typename A>
115 this->alloc.allocate(this->alloc_size(
n)));
118template<tagging_descriptor D,
typename A>
125 this->alloc.allocate(this->alloc_size(
n),
i));
128template<tagging_descriptor D,
typename A>
132 return block_type::from_storage_ptr(
133 this->alloc.reallocate(this->raw_from_ptr(p), this->alloc_size(
n))
137template<tagging_descriptor D,
typename A>
139 this->alloc.deallocate(this->raw_from_ptr(p), this->alloc_size(
n));
local class const
Definition animation.lua:7
Generic implementation of a malloc(3)-style allocator with headers.
Definition tagging.h:44
typename D::block_type block_type
Definition tagging.h:46
static auto alloc_size(std::size_t n)
Definition tagging.h:83
tagging_allocator(const allocator &a)
Definition tagging.h:65
static pointer to_ptr(char *p)
Definition tagging.h:88
void deallocate(pointer p, std::size_t n) noexcept
Definition tagging.h:138
typename D::value_type value_type
Definition tagging.h:47
tagging_allocator(void)=default
typename std::allocator_traits< A >::template rebind_alloc< char > allocator
Definition tagging.h:49
pointer allocate(std::size_t n) noexcept
Allocates n objects (n.b.: only one header is added).
Definition tagging.h:113
tagging_allocator(tagging_allocator &&) noexcept=default
tagging_allocator & operator=(const tagging_allocator &rhs)
Definition tagging.h:100
pointer reallocate(pointer p, std::size_t n) noexcept
Definition tagging.h:129
tagging_allocator(const tagging_allocator &rhs)
Definition tagging.h:61
static char * raw_from_ptr(pointer p)
Definition tagging.h:95
allocator alloc
Definition tagging.h:84
const allocator & get_allocator(void) const
Definition tagging.h:79
Definition fundamental.h:41
Associates a block type with an allocator.
Definition tagging.h:16
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
local data
Definition house0.lua:10
#define D(x)
Definition math_test.cpp:253
static constexpr bool has_realloc
Checks whether an allocator supports memory relocation.
Definition base.h:83
static constexpr bool has_typed_alloc
Checks whether an allocator supports typed memory allocations.
Definition base.h:94
constexpr To byte_cast(From p)
reinterpret_cast restricted to conversions from/to char/uchar.
Definition utils.h:121
Base class for allocators, implements a few basic operations.
Definition base.h:49