8 #ifndef BC_CORE_CONTEXT_WORKSPACE_H_ 9 #define BC_CORE_CONTEXT_WORKSPACE_H_ 15 namespace allocators {
18 template<
class SystemTag>
21 using system_tag = SystemTag;
37 if (sz == 0 || (m_data_sz - m_curr_index) > sz) {
41 if (!(m_curr_index==0)){
42 std::cout <<
"BC_Memory Allocation failure: \n" <<
43 "\tcurrent_stack_index == " << m_curr_index <<
" out of " << m_data_sz << \
44 "attempting to reserve " << sz <<
" bytes " << std::endl;
48 "Stack_Allocator reserve called while memory is still allocated");
60 "Stack_Allocator free called while memory is still allocated");
67 return m_data_sz - m_curr_index;
76 template<
class Allocator>
79 "Stack_Allocator set_allocator called while memory is still allocated");
84 if (m_curr_index + sz > m_data_sz) {
85 std::cout <<
"BC_Memory Allocation failure: \n" <<
86 "\tcurrent_stack_index == " << m_curr_index <<
" out of " << m_data_sz
87 <<
"\n\t attempting to allocate " << sz <<
" bytes, error: " << (m_curr_index + sz <= m_data_sz) << std::endl;
90 BC_ASSERT(!(m_curr_index + sz > m_data_sz),
91 "BC_Memory Allocation failure, attempting to allocate memory larger that workspace size");
93 Byte* mem = m_data + m_curr_index;
100 "BC_Memory Deallocation failure, attempting to deallocate already deallocated memory.");
102 BC_ASSERT(data == (m_data + m_curr_index - sz),
103 "BC_Memory Deallocation failure, attempting to deallocate memory out of order," 104 "\nStack_Allocator memory functions as a stack, deallocations must be in reverse order of allocations.");
117 return reinterpret_cast<T*
>(
allocate(sz *
sizeof(T)));
122 deallocate(reinterpret_cast<Byte*>(data), sz *
sizeof(T));
127 "Stack_Allocator Destructor called while memory is still allocated, Memory Leak Detected");
137 template<
class ValueType,
class SystemTag>
140 template<
class,
class>
144 std::shared_ptr<ws_base_t> ws_ptr;
178 ws_ptr->force_deallocate();
182 return ws_ptr->available_bytes();
186 return ws_ptr->allocated_bytes();
190 return ws_ptr->reserved_bytes();
193 template<
class Allocator>
195 ws_ptr->set_allocator(alloc);
199 return ws_ptr->template allocate<ValueType>(sz);
202 ws_ptr->template deallocate<ValueType>(data, sz);
std::false_type propagate_on_container_copy_construction
Definition: stack_allocator.h:150
size_t available_bytes() const
Definition: stack_allocator.h:181
void free()
Definition: stack_allocator.h:58
~Stack_Allocator_Base()
Definition: stack_allocator.h:125
T * allocate(std::size_t sz)
Definition: stack_allocator.h:116
void set_allocator(const Allocator &alloc)
Definition: polymorphic_allocator.h:179
Byte * allocate(std::size_t sz)
Definition: stack_allocator.h:83
ValueType * allocate(std::size_t sz)
Definition: stack_allocator.h:198
void deallocate(Byte *data, std::size_t sz)
Definition: stack_allocator.h:98
Stack_Allocator(const Stack_Allocator< T, SystemTag > &ws)
Definition: stack_allocator.h:161
size_t reserved_bytes() const
Definition: stack_allocator.h:72
int size_t
Definition: common.h:283
void deallocate(ValueType *data, std::size_t sz)
Definition: stack_allocator.h:201
Definition: allocators.h:20
An unsynced memory pool implemented as a stack.
Definition: stack_allocator.h:138
void set_allocator(Allocator alloc)
Definition: stack_allocator.h:77
void force_deallocate()
Definition: stack_allocator.h:177
size_t allocated_bytes() const
Definition: stack_allocator.h:185
size_t allocated_bytes() const
Definition: stack_allocator.h:69
void free()
Delete all reserved memory, if memory is currently allocated an error is thrown.
Definition: stack_allocator.h:173
Definition: stack_allocator.h:19
size_t reserved_bytes() const
Definition: stack_allocator.h:189
void force_deallocate()
Definition: stack_allocator.h:111
void reserve(std::size_t sz)
Definition: stack_allocator.h:36
Definition: allocators.h:17
Stack_Allocator_Base(std::size_t sz=0)
Definition: stack_allocator.h:32
void deallocate(value_type *data, std::size_t sz)
Definition: polymorphic_allocator.h:174
#define BC_ASSERT(condition, message)
Definition: common.h:185
value_type * allocate(std::size_t sz)
Definition: polymorphic_allocator.h:170
void deallocate(T *data, std::size_t sz)
Definition: stack_allocator.h:121
Definition: stack_allocator.h:153
size_t available_bytes() const
Definition: stack_allocator.h:66
void set_allocator(Allocator alloc)
Definition: stack_allocator.h:194
Stack_Allocator(int sz=0)
Definition: stack_allocator.h:157
void reserve(std::size_t sz)
Reserve an amount of memory in bytes.
Definition: stack_allocator.h:168
The Evaluator determines if an expression needs to be greedily optimized.
Definition: algorithms.h:22