17 #include <type_traits> 35 setBuffer(buffer, size);
41 *
this = std::move(other);
48 _buffer = other.buffer;
49 _freeBlocks = other._freeBlocks;
50 _freeBlockIndex = other._freeBlockIndex;
51 _numHeapAllocatedBlocks = other._numHeapAllocatedBlocks;
52 _spinlock = std::move(other._spinlock);
55 other._buffer =
nullptr;
56 other._freeBlocks =
nullptr;
57 other._freeBlockIndex = -1;
58 other._numHeapAllocatedBlocks = 0;
71 throw std::runtime_error(
"Null buffer");
74 throw std::runtime_error(
"Invalid allocator pool size");
80 throw std::bad_alloc();
82 _freeBlockIndex = size-1;
101 template <
typename T>
107 template <
typename T>
108 template <
typename... Args >
111 new((
void *)p) T(std::forward<Args>(args)...);
114 template <
typename T>
123 template <
typename T>
130 if (findContiguous(static_cast<index_type>(n)))
132 _freeBlockIndex -= (n - 1);
133 return reinterpret_cast<pointer>(&_buffer[_freeBlocks[_freeBlockIndex--]]);
136 ++_numHeapAllocatedBlocks;
141 template <
typename T>
152 _freeBlocks[++_freeBlockIndex] = blockIndex(p+i);
158 --_numHeapAllocatedBlocks;
159 assert(_numHeapAllocatedBlocks >= 0);
163 template <
typename T>
164 template <
typename... Args >
168 construct(p, std::forward<Args>(args)...);
172 template <
typename T>
179 template <
typename T>
182 return _size ? _size - _freeBlockIndex - 1 : 0;
185 template <
typename T>
188 return _numHeapAllocatedBlocks;
191 template <
typename T>
194 return _freeBlockIndex == _size-1;
197 template <
typename T>
200 return _freeBlockIndex == -1;
203 template <
typename T>
206 return reinterpret_cast<pointer>(_buffer);
209 template <
typename T>
212 return reinterpret_cast<pointer>(_buffer + _size);
215 template <
typename T>
216 bool ContiguousPoolManager<T>::isManaged(pointer p)
218 return (bufferStart() <= p) && (p < bufferEnd());
221 template <
typename T>
224 return static_cast<index_type>(reinterpret_cast<aligned_type*>(p) - _buffer);
227 template <
typename T>
228 bool ContiguousPoolManager<T>::findContiguous(index_type n)
230 if ((_freeBlockIndex + 1) < n) {
234 aligned_type* last = &_buffer[_freeBlocks[_freeBlockIndex]];
235 for (ssize_t i = _freeBlockIndex-1; i > _freeBlockIndex-n; --i) {
236 aligned_type* first = &_buffer[_freeBlocks[i]];
237 if ((last-first) != (_freeBlockIndex-i)) {
virtual ~ContiguousPoolManager()
Definition: quantum_contiguous_pool_manager_impl.h:62
const value_type * const_pointer
Definition: quantum_contiguous_pool_manager.h:46
uint16_t index_type
Definition: quantum_contiguous_pool_manager.h:50
Definition: quantum_spinlock.h:71
Provides fast (quasi zero-time) in-place allocation for STL containers. Objects are allocated from a ...
Definition: quantum_contiguous_pool_manager.h:40
Definition: quantum_buffer_impl.h:22
size_t allocatedBlocks() const
Definition: quantum_contiguous_pool_manager_impl.h:180
bool isFull() const
Definition: quantum_contiguous_pool_manager_impl.h:192
size_t allocatedHeapBlocks() const
Definition: quantum_contiguous_pool_manager_impl.h:186
void dispose(pointer p)
Definition: quantum_contiguous_pool_manager_impl.h:173
ContiguousPoolManager & operator=(const this_type &)=delete
value_type & reference
Definition: quantum_contiguous_pool_manager.h:47
value_type * pointer
Definition: quantum_contiguous_pool_manager.h:45
void construct(T *p, Args &&... args)
Definition: quantum_contiguous_pool_manager_impl.h:109
T value_type
Definition: quantum_contiguous_pool_manager.h:44
const value_type & const_reference
Definition: quantum_contiguous_pool_manager.h:48
void deallocate(pointer p, size_type=1)
Definition: quantum_contiguous_pool_manager_impl.h:142
void setBuffer(aligned_type *buffer, index_type size)
Definition: quantum_contiguous_pool_manager_impl.h:68
bool isEmpty() const
Definition: quantum_contiguous_pool_manager_impl.h:198
pointer create(Args &&... args)
Definition: quantum_contiguous_pool_manager_impl.h:165
pointer allocate(size_type=1, const_pointer=0)
Definition: quantum_contiguous_pool_manager_impl.h:125
size_type max_size() const
Definition: quantum_contiguous_pool_manager_impl.h:102
pointer address(reference x) const
Definition: quantum_contiguous_pool_manager_impl.h:90
ContiguousPoolManager()
Definition: quantum_contiguous_pool_manager_impl.h:28
storage_type::type aligned_type
Definition: quantum_contiguous_pool_manager.h:52
void destroy(pointer p)
Definition: quantum_contiguous_pool_manager_impl.h:115
size_t size_type
Definition: quantum_contiguous_pool_manager.h:49