22template<
typename T>
struct AlignedTHPAllocator
26 AlignedTHPAllocator() =
default;
28 template<
class U>
constexpr AlignedTHPAllocator(
const AlignedTHPAllocator<U>&)
noexcept { }
30 T *allocate(std::size_t n)
32 std::size_t bytes = n *
sizeof(T);
34 int res = posix_memalign(&ptr, hugepage_size, bytes);
35 if (res != 0 || ptr ==
nullptr)
36 throw std::bad_alloc();
37 madvise(ptr, bytes, MADV_HUGEPAGE);
38 return static_cast<T *
>(ptr);
41 void deallocate(T *p, std::size_t n)
noexcept