libcopp  1.1.0
stack_allocator_pool.h
Go to the documentation of this file.
1 #ifndef COPP_STACKCONTEXT_ALLOCATOR_POOL_H
2 #define COPP_STACKCONTEXT_ALLOCATOR_POOL_H
3 
4 #pragma once
5 
6 #include <assert.h>
7 #include <cstddef>
8 
11 
12 #ifdef COPP_HAS_ABI_HEADERS
13 #include COPP_ABI_PREFIX
14 #endif
15 
16 namespace copp {
17  struct stack_context;
18 
19  namespace allocator {
20 
25  template <typename TPool>
27  public:
28  typedef TPool pool_t;
29 
30  public:
31  stack_allocator_pool() UTIL_CONFIG_NOEXCEPT {}
32  stack_allocator_pool(const std::shared_ptr<pool_t> &p) UTIL_CONFIG_NOEXCEPT : pool_(p) {}
34 
41  void attach(const std::shared_ptr<pool_t> &p) UTIL_CONFIG_NOEXCEPT { pool_ = p; }
42 
49  void allocate(stack_context &ctx, std::size_t) UTIL_CONFIG_NOEXCEPT {
50  assert(pool_);
51  if (pool_) {
52  pool_->allocate(ctx);
53  }
54  }
55 
60  void deallocate(stack_context &ctx) UTIL_CONFIG_NOEXCEPT {
61  assert(pool_);
62  if (pool_) {
63  pool_->deallocate(ctx);
64  }
65  }
66 
67  private:
68  std::shared_ptr<pool_t> pool_;
69  };
70  } // namespace allocator
71 } // namespace copp
72 
73 #ifdef COPP_HAS_ABI_HEADERS
74 #include COPP_ABI_SUFFIX
75 #endif
76 
77 #endif
void deallocate(stack_context &ctx) UTIL_CONFIG_NOEXCEPT
void attach(const std::shared_ptr< pool_t > &p) UTIL_CONFIG_NOEXCEPT
导入智能指针库 Licensed under the MIT licenses.
void allocate(stack_context &ctx, std::size_t) UTIL_CONFIG_NOEXCEPT
stack_allocator_pool(const std::shared_ptr< pool_t > &p) UTIL_CONFIG_NOEXCEPT
memory allocator this allocator will maintain buffer using malloc/free function