/workspaces/astro/sol3-sdk/cpp/sol3/net/buffer_pool.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/net/buffer_pool.h Source File
Space-ng SDK
buffer_pool.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 
3 #pragma once
4 
6 
7 #include <cstddef>
8 #include <cstdint>
9 #include <memory>
10 #include <vector>
11 
12 namespace sol3::net {
14 
21 class BufferPool {
22  public:
23  explicit BufferPool(std::size_t reserve_bytes);
24  BufferPool(BufferPool const&) = delete;
25  BufferPool& operator=(BufferPool const&) = delete;
26  BufferPool(BufferPool&&) = delete;
28  ~BufferPool() = default;
29 
30  // The returned vector has size() == 0 and capacity() >= reserve_bytes_
31  std::shared_ptr<std::vector<uint8_t>> acquire();
32 
33  private:
34  using FreeList = std::vector<std::unique_ptr<std::vector<uint8_t>>>;
36 
37  std::shared_ptr<ThreadSafeFreeList> free_list_ =
38  std::make_shared<ThreadSafeFreeList>();
39  std::size_t reserve_bytes_;
40 };
41 
42 } // namespace sol3::net
Small helper for read/write access to a value guarded by a shared mutex.
Definition: thread_safe_value.h:13
Definition: buffer_pool.h:21
BufferPool & operator=(BufferPool &&)=delete
BufferPool(std::size_t reserve_bytes)
BufferPool & operator=(BufferPool const &)=delete
BufferPool(BufferPool const &)=delete
std::shared_ptr< std::vector< uint8_t > > acquire()
BufferPool(BufferPool &&)=delete
Definition: buffer_pool.h:12