We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have a vague recollection of testing this already but I'm not 100%
sample code
#include <limits> #include <thread> #include <new> #include <stdlib.h> // posix_memalign #include <sys/mman.h> // madvise template <typename T> struct thp_allocator { constexpr static std::size_t huge_page_size = 1 << 21; // 2 MiB using value_type = T; thp_allocator() = default; template <class U> constexpr thp_allocator(const thp_allocator<U> &) noexcept {} T *allocate(std::size_t n) { if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) { throw std::bad_alloc(); } void *p = nullptr; posix_memalign(&p, huge_page_size, n * sizeof(T)); madvise(p, n * sizeof(T), MADV_HUGEPAGE); if (p == nullptr) { throw std::bad_alloc(); } return static_cast<T *>(p); } void deallocate(T *p, std::size_t n) { std::free(p); } }; int main(){ thp_allocator<double> thp; auto m = thp.allocate(1000); }
The text was updated successfully, but these errors were encountered:
PhilipDeegan
No branches or pull requests
I have a vague recollection of testing this already but I'm not 100%
sample code
The text was updated successfully, but these errors were encountered: