barretenberg
Loading...
Searching...
No Matches
slab_allocator.hpp
1#pragma once
2#include "./assert.hpp"
3#include "./log.hpp"
4#include <list>
5#include <map>
6#include <memory>
7#include <unordered_map>
8#ifndef NO_MULTITHREADING
9#include <mutex>
10#endif
11
12namespace barretenberg {
13
28void init_slab_allocator(size_t circuit_subgroup_size);
29
34std::shared_ptr<void> get_mem_slab(size_t size);
35
40void* get_mem_slab_raw(size_t size);
41
42void free_mem_slab_raw(void*);
43
47template <typename T> class ContainerSlabAllocator {
48 public:
49 using value_type = T;
50 using pointer = T*;
51 using const_pointer = const T*;
52 using size_type = std::size_t;
53
54 template <typename U> struct rebind {
56 };
57
58 pointer allocate(size_type n)
59 {
60 // info("ContainerSlabAllocator allocating: ", n * sizeof(T));
61 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
62 return reinterpret_cast<pointer>(get_mem_slab_raw(n * sizeof(T)));
63 }
64
65 void deallocate(pointer p, size_type /*unused*/) { free_mem_slab_raw(p); }
66
67 friend bool operator==(const ContainerSlabAllocator<T>& /*unused*/, const ContainerSlabAllocator<T>& /*unused*/)
68 {
69 return true;
70 }
71
72 friend bool operator!=(const ContainerSlabAllocator<T>& /*unused*/, const ContainerSlabAllocator<T>& /*unused*/)
73 {
74 return false;
75 }
76};
77
78} // namespace barretenberg
Definition: slab_allocator.hpp:47
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16
void init_slab_allocator(size_t circuit_subgroup_size)
Definition: slab_allocator.cpp:204
void * get_mem_slab_raw(size_t size)
Definition: slab_allocator.cpp:219
std::shared_ptr< void > get_mem_slab(size_t size)
Definition: slab_allocator.cpp:214
Definition: slab_allocator.hpp:54