Exemple #1
0
uint8_t* BlockPoolBase::resizeLastBlock( size_t newSize )
{
    const auto alignedNewSize = getAlignedSize( newSize, alignment_ );
    const auto currentBlockSize = lastBlockSize();

    LOG(logDEBUG2) << "Resizing block "
                    << " from " << currentBlockSize
                    << " to " << newSize
                    << " aligned " << alignedNewSize
                    << " alloc " << allocationSize_;

    if ( alignedNewSize <= currentBlockSize ) {
        allocationSize_ -= ( currentBlockSize - alignedNewSize );
    }
    else {
        const auto delta = alignedNewSize - currentBlockSize;
        LOG(logDEBUG2) << "Increasing last block size by " << delta;

        if ( allocationSize_ + delta >= pool_.size() ) {
            increasePool( pool_ );
        }
        allocationSize_ += delta;
    }

    LOG(logDEBUG2) << "Resized block, alloc " << allocationSize_;

    return pool_.data() + blockIndex_.back();
}
Exemple #2
0
void* Pool::allocate()
{
	char* tempptr = freeptr;

	unsigned int addr = *(unsigned int*)freeptr;
	freeptr = (char*)(addr);
	if(freeptr == endptr)
		increasePool();
	return tempptr;
}
Exemple #3
0
Pool::Pool(size_t eSize,size_t bSize)
{
	std::cout << "Initializing a pool with element size " << eSize;
	std::cout << " and block size " << bSize << std::endl;

	elemSize = eSize;
	blockSize = bSize;

	len = eSize * bSize;
	increasePool();	
}
Exemple #4
0
uint8_t* BlockPoolBase::getBlock( size_t elementsCount )
{
    const auto requiredSize = getBlockStorageSize( elementsCount, elementSize_, alignment_ );

    const auto alignedAllocationSize = getAlignedSize(allocationSize_, alignment_);

    LOG(logDEBUG2) << "Get block " << elementSize_
                   << " pool " << pool_.size()
                   << " alloc " << allocationSize_
                   << " blocks " << blockIndex_.size();

    if ( alignedAllocationSize + requiredSize >= pool_.size() ) {
        increasePool( pool_ );
    }

    blockIndex_.push_back( alignedAllocationSize );
    allocationSize_ = alignedAllocationSize + requiredSize;

    return pool_.data() + blockIndex_.back();
}