14 void* data = calloc(nmemb,
sizeof(T));
17 const char* msg =
"internal error: memory allocation failed!\n";
28 return *calloc_or_throw<T>(1);
43 template <
class T,
typename... Args>
46 T* temp = calloc_or_throw<T>(1);
47 new (temp) T(std::forward<Args>(args)...);
48 return std::unique_ptr<T, free_fn>(temp, destroy_free<T>);
57 size_t length = nmemb *
sizeof(T);
59 if (0 != posix_memalign(&data, sysconf(_SC_PAGE_SIZE), length))
61 const char* msg =
"internal error: memory allocation failed!\n";
67 const char* msg =
"internal error: memory allocation failed!\n";
71 memset(data, 0, length);
83 if (0 != madvise(data, length, MADV_MERGEABLE))
85 const char* msg =
"internal warning: marking memory as ksm mergeable failed!\n";
91 #define calloc_mergable_or_throw calloc_or_throw T * calloc_or_throw(size_t nmemb)
free_ptr< T > scoped_calloc_or_throw(Args &&... args)
std::unique_ptr< T, free_fn > free_ptr
void destroy_free(void *temp)
#define calloc_mergable_or_throw
#define THROW_OR_RETURN(...)