Botan 2.19.3
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/types.h>
11#include <botan/mutex.h>
12#include <vector>
13#include <deque>
14#include <map>
15
16namespace Botan {
17
18class Bucket;
19
21 {
22 public:
23 /**
24 * Initialize a memory pool. The memory is not owned by *this,
25 * it must be freed by the caller.
26 * @param pages a list of pages to allocate from
27 * @param page_size the system page size, each page should
28 * point to exactly this much memory.
29 */
30 Memory_Pool(const std::vector<void*>& pages,
31 size_t page_size);
32
34
35 void* allocate(size_t size);
36
37 bool deallocate(void* p, size_t size) noexcept;
38
39 Memory_Pool(const Memory_Pool&) = delete;
41
44
45 private:
46 const size_t m_page_size = 0;
47
48 mutex_type m_mutex;
49
50 std::deque<uint8_t*> m_free_pages;
51 std::map<size_t, std::deque<Bucket>> m_buckets_for;
52 uintptr_t m_min_page_ptr;
53 uintptr_t m_max_page_ptr;
54 };
55
56}
57
58#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