コード例 #1
0
ファイル: alloc_pmr.hpp プロジェクト: hioa-cs/IncludeOS
  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);
    }
  }
コード例 #2
0
ファイル: memory.cpp プロジェクト: aonorin/vpp
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");
}