Botan 2.19.5 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
16 namespace Botan {
17
18 class Bucket;
19
20 class BOTAN_TEST_API Memory_Pool final
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
33 ~Memory_Pool();
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;
40 Memory_Pool(Memory_Pool&&) = delete;
41
42 Memory_Pool& operator=(const Memory_Pool&) = delete;
43 Memory_Pool& operator=(Memory_Pool&&) = delete;
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
Botan::Memory_Pool
Definition: mem_pool.h:21
Botan::Memory_Pool::Memory_Pool
Memory_Pool(Memory_Pool &&)=delete
Botan::Memory_Pool::operator=
Memory_Pool & operator=(Memory_Pool &&)=delete
Botan::Memory_Pool::Memory_Pool
Memory_Pool(const Memory_Pool &)=delete
Botan::Memory_Pool::operator=
Memory_Pool & operator=(const Memory_Pool &)=delete
Botan::noop_mutex
Definition: mutex.h:46
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_TEST_API
#define BOTAN_TEST_API
Definition: compiler.h:51
Botan
Definition: alg_id.cpp:13