// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include namespace vespalib { /** * std compliant allocator that will use a smart allocator * that uses mmap prefering huge pages for large allocations. * This is a good fit for use with std::vector and std::deque. */ template class allocator_large { public: allocator_large() noexcept : _allocator(alloc::MemoryAllocator::select_allocator()) {} using value_type = T; constexpr T * allocate(std::size_t n) { return static_cast(_allocator->alloc(n*sizeof(T)).get()); } void deallocate(T * p, std::size_t n) { _allocator->free(p, n*sizeof(T)); } const alloc::MemoryAllocator * allocator() const { return _allocator; } private: const alloc::MemoryAllocator * _allocator; }; template< class T1, class T2 > constexpr bool operator==( const allocator_large& lhs, const allocator_large& rhs ) noexcept { return lhs.allocator() == rhs.allocator(); } }