//! Construct a block of given size. static ByteBlockPtr Allocate( size_t block_size, BlockPool& block_pool) { // this counts only the bytes and excludes the header. why? -tb block_pool.AllocateBlock(block_size); // allocate a new block of uninitialized memory ByteBlock* block = static_cast<ByteBlock*>( operator new ( sizeof(common::ReferenceCount) + sizeof(head) + block_size)); // initialize block using constructor new (block)ByteBlock(block_size, &block_pool); // wrap allocated ByteBlock in a shared_ptr. TODO(tb) figure out how to do // this whole procedure with std::make_shared. return ByteBlockPtr(block); }
ByteBlockPtr AllocateByteBlock(size_t block_size) final { if (available_ < block_size) return ByteBlockPtr(); available_ -= block_size; return BlockSink::AllocateByteBlock(block_size); }
//! Releases the reference to the ByteBlock and resets book-keeping info void Release() { byte_block_ = ByteBlockPtr(); }