void Pmr_resource::do_deallocate(void* ptr, std::size_t s, std::size_t a) { Expects(s != 0); // POSIX malloc will allow size 0, but return nullptr. bool trigger_non_full = UNLIKELY(full() and non_full != nullptr); bool trigger_avail_thresh = UNLIKELY(allocatable() < avail_thresh and allocatable() + s >= avail_thresh and avail != nullptr); pool_->deallocate(ptr,s,a); deallocs++; used -= s; if (UNLIKELY(trigger_avail_thresh)) { Ensures(allocatable() >= avail_thresh); Ensures(avail != nullptr); avail(*this); } if (UNLIKELY(trigger_non_full)) { Ensures(!full()); Ensures(non_full != nullptr); non_full(*this); } }
Allocation DeviceMemory::alloc(size_t size, size_t alignment, AllocationType type) { auto allocation = allocatable(size, alignment, type); if(allocation.size > 0) return allocSpecified(allocation.offset, allocation.size, type); throw std::runtime_error("vpp::DeviceMemory::alloc: not enough memory left"); }