aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/mem_pool/mem_pool.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-12-27 21:04:28 -0500
committerJack Lloyd <[email protected]>2019-01-04 21:23:25 -0500
commite2ee85c5de7df54953559d80e9889dd550550699 (patch)
tree7d2d7daa45833cc6722ed3191e6c79374b141d6d /src/lib/utils/mem_pool/mem_pool.h
parent4b1252bc1410d9c6af61ca20f5a1e72fa2d440d4 (diff)
New Memory_Pool implementation
Quite a bit faster than the old version, and with better properties wrt alignment
Diffstat (limited to 'src/lib/utils/mem_pool/mem_pool.h')
-rw-r--r--src/lib/utils/mem_pool/mem_pool.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/lib/utils/mem_pool/mem_pool.h b/src/lib/utils/mem_pool/mem_pool.h
index c9c836a9c..8f497310c 100644
--- a/src/lib/utils/mem_pool/mem_pool.h
+++ b/src/lib/utils/mem_pool/mem_pool.h
@@ -9,10 +9,13 @@
#include <botan/types.h>
#include <botan/mutex.h>
-#include <vector>
+#include <deque>
+#include <map>
namespace Botan {
+class Bucket;
+
class BOTAN_TEST_API Memory_Pool final
{
public:
@@ -20,37 +23,34 @@ class BOTAN_TEST_API Memory_Pool final
* Initialize a memory pool. The memory is not owned by *this,
* it must be freed by the caller.
* @param pool the pool
- * @param pool_size size of pool
+ * @param page_count size of pool in page_size chunks
* @param page_size some nominal page size (does not need to match
* the system page size)
- * @param min_allocation return null for allocs for smaller amounts
- * @param max_allocation return null for allocs of larger amounts
- * @param align_bit align all returned memory to (1<<align_bit) bytes
*/
Memory_Pool(uint8_t* pool,
- size_t pool_size,
- size_t page_size,
- size_t min_allocation,
- size_t max_allocation,
- uint8_t align_bit);
+ size_t page_count,
+ size_t page_size);
+
+ ~Memory_Pool();
void* allocate(size_t size);
bool deallocate(void* p, size_t size) noexcept;
Memory_Pool(const Memory_Pool&) = delete;
+ Memory_Pool(Memory_Pool&&) = delete;
Memory_Pool& operator=(const Memory_Pool&) = delete;
+ Memory_Pool& operator=(Memory_Pool&&) = delete;
private:
const size_t m_page_size = 0;
- const size_t m_min_alloc = 0;
- const size_t m_max_alloc = 0;
- const uint8_t m_align_bit = 0;
mutex_type m_mutex;
- std::vector<std::pair<size_t, size_t>> m_freelist;
+ std::deque<uint8_t*> m_free_pages;
+ std::map<size_t, std::deque<Bucket>> m_buckets_for;
+
uint8_t* m_pool = nullptr;
size_t m_pool_size = 0;
};