#ifndef TWO_MALLOCS_HPP #define TWO_MALLOCS_HPP #include // dlmalloc is only used on linux. extern "C" { #ifdef __linux__ void* dlmalloc(size_t x); void dlfree(void *p); void* dlrealloc(void*, size_t); #else void* dlmalloc(size_t x) { return malloc(x); } void dlfree(void *p) { free(p); } void* dlrealloc(void *p, size_t x) { return realloc(p,x); } #endif } // Return the current state of the dlmalloc allocator as a 30-bit hash. extern int dlmalloc_hash(); // EngAllocator: a class meant to be used as an STL Allocator. // Causes objects to be allocated using dlmalloc and dlfree. template class EngAllocator { public: using value_type = T; EngAllocator() noexcept {} template EngAllocator(EngAllocator const&) noexcept {} value_type* allocate(std::size_t n) { return static_cast(dlmalloc(n*sizeof(value_type))); } void deallocate(value_type* p, std::size_t) noexcept { dlfree(p); } }; template bool operator==(EngAllocator const&, EngAllocator const&) noexcept { return true; } template bool operator!=(EngAllocator const&, EngAllocator const&) noexcept { return false; } // namespace eng { // template // using hash = std::hash; // template // using less = std::less; // template // using equal_to = std::equal_to; // template // using char_traits = std::char_traits; // template // using pair = std::pair; // } #endif // TWO_MALLOCS_HPP