Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
slab_allocator.hpp
Go to the documentation of this file.
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#include <vector>
9#ifndef NO_MULTITHREADING
10#include <mutex>
11#endif
12
13namespace bb {
14
29void init_slab_allocator(size_t circuit_subgroup_size);
30
36
41void* get_mem_slab_raw(size_t size);
42
43void free_mem_slab_raw(void*);
44
48template <typename T> class ContainerSlabAllocator {
49 public:
50 using value_type = T;
51 using pointer = T*;
52 using const_pointer = const T*;
54
55 template <typename U> struct rebind {
57 };
58
60 {
61 // info("ContainerSlabAllocator allocating: ", n * sizeof(T));
62 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
63 return reinterpret_cast<pointer>(get_mem_slab_raw(n * sizeof(T)));
64 }
65
66 void deallocate(pointer p, size_type /*unused*/) { free_mem_slab_raw(p); }
67
68 friend bool operator==(const ContainerSlabAllocator<T>& /*unused*/, const ContainerSlabAllocator<T>& /*unused*/)
69 {
70 return true;
71 }
72
73 friend bool operator!=(const ContainerSlabAllocator<T>& /*unused*/, const ContainerSlabAllocator<T>& /*unused*/)
74 {
75 return false;
76 }
77};
78
83
84} // namespace bb
pointer allocate(size_type n)
friend bool operator!=(const ContainerSlabAllocator< T > &, const ContainerSlabAllocator< T > &)
friend bool operator==(const ContainerSlabAllocator< T > &, const ContainerSlabAllocator< T > &)
void deallocate(pointer p, size_type)
Entry point for Barretenberg command-line interface.
void * get_mem_slab_raw(size_t size)
std::shared_ptr< void > get_mem_slab(size_t size)
std::vector< T, bb::ContainerSlabAllocator< T > > SlabVector
A vector that uses the slab allocator.
void init_slab_allocator(size_t circuit_subgroup_size)
void free_mem_slab_raw(void *p)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13