5 #ifndef UAVCAN_HELPERS_HEAP_BASED_POOL_ALLOCATOR_HPP_INCLUDED
6 #define UAVCAN_HELPERS_HEAP_BASED_POOL_ALLOCATOR_HPP_INCLUDED
71 uint16_t block_capacity_hard_limit = 0) :
72 capacity_soft_limit_(block_capacity_soft_limit),
73 capacity_hard_limit_((block_capacity_hard_limit > 0) ? block_capacity_hard_limit :
76 num_reserved_blocks_(0),
77 num_allocated_blocks_(0),
89 if (num_allocated_blocks_ > 0)
91 UAVCAN_TRACE(
"HeapBasedPoolAllocator",
"%u BLOCKS LEAKED", num_allocated_blocks_);
102 if (size > BlockSize)
111 Node*
const p = reserve_;
115 reserve_ = reserve_->next;
116 num_allocated_blocks_++;
120 if (num_reserved_blocks_ >= capacity_hard_limit_)
127 void*
const m = std::malloc(
sizeof(
Node));
133 num_reserved_blocks_++;
134 num_allocated_blocks_++;
150 Node*
const node =
static_cast<Node*
>(
const_cast<void*
>(ptr));
151 node->next = reserve_;
154 num_allocated_blocks_--;
184 reserve_ = reserve_->next;
185 num_reserved_blocks_--;
204 return num_allocated_blocks_;
214 return num_reserved_blocks_;