/* * 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_SRC_MEM_POOLINGALLOCATOR_H #define SQUID_SRC_MEM_POOLINGALLOCATOR_H #include "mem/forward.h" #include /// 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(memAllocBuf(n*sizeof(value_type), nullptr)); } void deallocate(value_type *vp, std::size_t n) noexcept { memFreeBuf(n*sizeof(value_type), vp); } template struct rebind { typedef PoolingAllocator other; }; template void construct(U *p, Args && ... args) { new((void *)p) U(std::forward(args)...); } 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_SRC_MEM_POOLINGALLOCATOR_H */