Botan 3.6.1
Crypto and TLS for C&
mem_pool.h
Go to the documentation of this file.
1/*
2* (C) 2018 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_MEM_POOL_H_
8#define BOTAN_MEM_POOL_H_
9
10#include <botan/mutex.h>
11#include <botan/types.h>
12#include <deque>
13#include <map>
14#include <vector>
15
16namespace Botan {
17
18class Bucket;
19
21 public:
22 /**
23 * Initialize a memory pool. The memory is not owned by *this,
24 * it must be freed by the caller.
25 * @param pages a list of pages to allocate from
26 * @param page_size the system page size, each page should
27 * point to exactly this much memory.
28 */
29 Memory_Pool(const std::vector<void*>& pages, size_t page_size);
30
32
33 void* allocate(size_t size);
34
35 bool deallocate(void* p, size_t size) noexcept;
36
37 Memory_Pool(const Memory_Pool&) = delete;
39
42
43 private:
44 const size_t m_page_size = 0;
45
46 mutex_type m_mutex;
47
48 std::deque<uint8_t*> m_free_pages;
49 std::map<size_t, std::deque<Bucket>> m_buckets_for;
50 uintptr_t m_min_page_ptr;
51 uintptr_t m_max_page_ptr;
52};
53
54} // namespace Botan
55
56#endif
Memory_Pool(Memory_Pool &&)=delete
Memory_Pool & operator=(Memory_Pool &&)=delete
Memory_Pool(const Memory_Pool &)=delete
Memory_Pool & operator=(const Memory_Pool &)=delete
int(* final)(unsigned char *, CTX *)
#define BOTAN_TEST_API
Definition compiler.h:51