PoolingAllocator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_MEM_POOLINGALLOCATOR_H
10 #define SQUID_SRC_MEM_POOLINGALLOCATOR_H
11 
12 #include "mem/forward.h"
13 
14 #include <utility>
15 
17 template <class Value>
19 {
20 public:
21  /* STL Allocator API */
22  using value_type = Value;
23  PoolingAllocator() noexcept {}
24  template <class Other> PoolingAllocator(const PoolingAllocator<Other> &) noexcept {}
25  value_type *allocate(std::size_t n) { return static_cast<value_type*>(memAllocBuf(n*sizeof(value_type), nullptr)); }
26  void deallocate(value_type *vp, std::size_t n) noexcept { memFreeBuf(n*sizeof(value_type), vp); }
27 
28  template <class OtherValue>
29  struct rebind {
31  };
32 
33  template<class U, class ... Args> void construct(U *p, Args && ... args) { new((void *)p) U(std::forward<Args>(args)...); }
34  template<typename OtherValue> void destroy(OtherValue *p) { p->~OtherValue(); }
35 };
36 
37 template <class L, class R>
38 inline bool
40 {
41  return true;
42 }
43 
44 template <class L, class R>
45 inline bool
47 {
48  return !(l == r);
49 }
50 
51 #endif /* SQUID_SRC_MEM_POOLINGALLOCATOR_H */
52 
void * memAllocBuf(size_t net_size, size_t *gross_size)
Definition: minimal.cc:46
bool operator==(const PoolingAllocator< L > &, const PoolingAllocator< R > &) noexcept
int const char size_t
Definition: stub_liblog.cc:83
PoolingAllocator(const PoolingAllocator< Other > &) noexcept
PoolingAllocator< OtherValue > other
STL Allocator that uses Squid memory pools for memory management.
value_type * allocate(std::size_t n)
void destroy(OtherValue *p)
bool operator!=(const PoolingAllocator< L > &l, const PoolingAllocator< R > &r) noexcept
void construct(U *p, Args &&... args)
PoolingAllocator() noexcept
void deallocate(value_type *vp, std::size_t n) noexcept
void memFreeBuf(size_t size, void *)
Definition: minimal.cc:67

 

Introduction

Documentation

Support

Miscellaneous