mCRL2
Loading...
Searching...
No Matches
block_allocator.h
Go to the documentation of this file.
1// Author(s): Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#ifndef MCRL2_UTILITIES_BLOCK_ALLOCATOR_H_
11#define MCRL2_UTILITIES_BLOCK_ALLOCATOR_H_
12
13#include "memory_pool.h"
14
15#include <memory>
16#include <stddef.h>
17
18namespace mcrl2
19{
20namespace utilities
21{
22
26template <class T,
27 std::size_t ElementsPerBlock = 1024,
28 bool ThreadSafe = false>
29class block_allocator : public memory_pool<T, ElementsPerBlock, ThreadSafe>
30{
31private:
33
34public:
35 using value_type = T;
36 using size_type = std::size_t;
37 using difference_type = std::ptrdiff_t;
38
39 template <class U>
40 struct rebind
41 {
43 };
44
45 block_allocator() = default;
46
49 T* allocate(size_type n, const void* hint = nullptr)
50 {
51 if (n != 1 || hint)
52 {
53 throw std::bad_alloc();
54 }
55
56 return super::allocate();
57 }
58
62 {
64 }
65
66 // Move assignment and construction is possible.
69};
70
71} // namespace utilities
72} // namespace mcrl2
73
74#endif
The block allocator provides the allocator interface for the memory pool class. As such is can be use...
block_allocator & operator=(block_allocator &&)=default
block_allocator(block_allocator &&)=default
T * allocate(size_type n, const void *hint=nullptr)
The memory pool allocates elements of size T from blocks.
Definition memory_pool.h:34
T * allocate()
Reuses memory from block and allocates a new block when no slots are free.
Definition memory_pool.h:80
void deallocate(T *pointer)
Free the memory used by the given pointer that has been allocated by this pool.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
block_allocator< U, ElementsPerBlock, ThreadSafe > other