#ifndef ENG_MALLOC_HPP #define ENG_MALLOC_HPP #include #include #include #include #include #include #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; template> using basic_string = std::basic_string>; template> using basic_stringstream = std::basic_stringstream>; template using vector = std::vector>; template> using map = std::map>>; template, class E=equal_to> using unordered_map = std::unordered_map>>; template> using set = std::set>; template, class E=equal_to> using unordered_set = std::unordered_set>; using string = basic_string; using stringstream = basic_stringstream; } #endif // ENG_MALLOC_HPP