7 template <std::
size_t N>
10 static const std::size_t alignment = 16;
11 alignas(alignment)
char buf_[N];
15 pointer_in_buffer(
char* p) noexcept
16 {
return buf_ <= p && p <= buf_ + N;}
19 arena() noexcept : ptr_(buf_) {}
20 ~
arena() {ptr_ =
nullptr;}
24 char* allocate(std::size_t n);
25 void deallocate(
char* p, std::size_t n) noexcept;
27 static constexpr std::size_t size() {
return N;}
28 std::size_t used()
const {
return static_cast<std::size_t
>(ptr_ - buf_);}
29 void reset() {ptr_ = buf_;}
32 template <std::
size_t N>
36 assert(pointer_in_buffer(ptr_) &&
"short_alloc has outlived arena");
37 if (buf_ + N - ptr_ >= n)
43 return static_cast<char*
>(::operator
new(n));
46 template <std::
size_t N>
50 assert(pointer_in_buffer(ptr_) &&
"short_alloc has outlived arena");
51 if (pointer_in_buffer(p))
60 template <
class T, std::
size_t N>
77 T* allocate(std::size_t n)
79 return reinterpret_cast<T*
>(a_.allocate(n*
sizeof(T)));
81 void deallocate(T* p, std::size_t n) noexcept
83 a_.deallocate(reinterpret_cast<char*>(p), n*
sizeof(T));
86 template <
class T1, std::
size_t N1,
class U, std::
size_t M>
91 template <
class U, std::
size_t M>
friend class short_alloc;
94 template <
class T, std::
size_t N,
class U, std::
size_t M>
99 return N == M && &x.a_ == &y.a_;
102 template <
class T, std::
size_t N,
class U, std::
size_t M>
110 #endif // SHORT_ALLOC_H
Definition: short_alloc.hpp:8
const int operator!=(const BigFloat< T > &lhs, const BigFloat< T > &rhs)
Definition: BigFloat.hpp:435
Definition: short_alloc.hpp:61
Definition: short_alloc.hpp:68
const int operator==(const BigFloat< T > &lhs, const BigFloat< T > &rhs)
Definition: BigFloat.hpp:423