/* * Copyright (C) 1996-2023 The Squid Software Foundation and contributors * * Squid software is distributed under GPLv2+ license and includes * contributions from numerous individuals and organizations. * Please see the COPYING and CONTRIBUTORS files for details. */ #ifndef SQUID_MEM_POOLINGALLOCATOR_H #define SQUID_MEM_POOLINGALLOCATOR_H #include "mem/forward.h" /// STL Allocator that uses Squid memory pools for memory management template class PoolingAllocator { public: /* STL Allocator API */ using value_type = Value; PoolingAllocator() noexcept {} template PoolingAllocator(const PoolingAllocator &) noexcept {} value_type *allocate(std::size_t n) { return static_cast(memAllocRigid(n*sizeof(value_type))); } void deallocate(value_type *vp, std::size_t n) noexcept { memFreeRigid(vp, n*sizeof(value_type)); } // The following declarations are only necessary for compilers that do not // fully support C++11 Allocator-related APIs, such as GCC v4.8. // TODO: Remove after dropping support for such compilers. using size_type = size_t; using pointer = Value*; using const_pointer = const Value*; using reference = Value&; using const_reference = const Value&; template struct rebind { typedef PoolingAllocator other; }; template void destroy(OtherValue *p) { p->~OtherValue(); } }; template inline bool operator ==(const PoolingAllocator&, const PoolingAllocator&) noexcept { return true; } template inline bool operator !=(const PoolingAllocator &l, const PoolingAllocator &r) noexcept { return !(l == r); } #endif /* SQUID_MEM_POOLINGALLOCATOR_H */