void* allocInNewBlock(size_t bytes) { size_t capacity = _nextBlockCapacity; if (bytes > capacity) capacity = bytes; if (!addNewBlock(capacity)) return NULL; _nextBlockCapacity *= 2; return allocInHead(bytes); }
void* allocInNewBlock(size_t bytes) { size_t capacity = FIRST_BLOCK_CAPACITY; if (_head != NULL) capacity = _head->capacity * 2; if (bytes > capacity) capacity = bytes; if (!addNewBlock(capacity)) return NULL; return allocInHead(bytes); }
void CopiedSpace::init() { m_toSpace = &m_blocks1; m_fromSpace = &m_blocks2; if (!addNewBlock()) CRASH(); }
bool ReplayBuffer<T>::init( size_t number_preallocated_objects ) { // make sure *clean* usage assert( !m_pp_blocks ); assert( number_preallocated_objects ); m_block_size = number_preallocated_objects; if( !addNewBlock() ) return false; return true; }
CheckedBoolean CopiedSpace::tryAllocateSlowCase(size_t bytes, void** outPtr) { if (isOversize(bytes)) return tryAllocateOversize(bytes, outPtr); m_heap->didAllocate(m_allocator.currentCapacity()); if (!addNewBlock()) { *outPtr = 0; return false; } *outPtr = m_allocator.allocate(bytes); ASSERT(*outPtr); return true; }
RModel::RModel( RDictionary *dictionary ) { printf( "RModel: Creating new model.\n" ); this->dictionary = dictionary; // Create initial blocks. printf( "RModel: \n" ); for( int x = 0; x < 3; x++ ) { for( int y = 0; y < 3; y++ ) { addNewBlock( x, y ); printf( " Pushed back a block @ %d, %d\n", x, y ); } } // Update the active blocks. updateActiveBlocks( 1, 1 ); // Create the player. }
void CopiedSpace::doneCopying() { { MutexLocker locker(m_loanedBlocksLock); while (m_numberOfLoanedBlocks > 0) m_loanedBlocksCondition.wait(m_loanedBlocksLock); } ASSERT(m_inCopyingPhase); m_inCopyingPhase = false; while (!m_fromSpace->isEmpty()) { CopiedBlock* block = static_cast<CopiedBlock*>(m_fromSpace->removeHead()); if (block->m_isPinned) { block->m_isPinned = false; // We don't add the block to the toSpaceSet because it was never removed. ASSERT(m_toSpaceSet.contains(block)); m_toSpaceFilter.add(reinterpret_cast<Bits>(block)); m_toSpace->push(block); continue; } m_toSpaceSet.remove(block); m_heap->blockAllocator().deallocate(block); } CopiedBlock* curr = static_cast<CopiedBlock*>(m_oversizeBlocks.head()); while (curr) { CopiedBlock* next = static_cast<CopiedBlock*>(curr->next()); if (!curr->m_isPinned) { m_oversizeBlocks.remove(curr); curr->m_allocation.deallocate(); } else curr->m_isPinned = false; curr = next; } if (!m_toSpace->head()) { if (!addNewBlock()) CRASH(); } else m_allocator.resetCurrentBlock(static_cast<CopiedBlock*>(m_toSpace->head())); }
T* ReplayBuffer<T>::getNewObject() { // make sure initialization was called properly assert( m_pp_blocks ); assert( m_number_blocks ); if( !m_healthy ) return NULL; // check, if we need a new block if( m_number_objects_used == (m_block_size*m_number_blocks) ) { // we need a new block if( !addNewBlock() ) return NULL; } // get current frame T* block_current = m_pp_blocks[ m_number_blocks-1 ]; size_t new_in_block_idx = m_number_objects_used % m_block_size; T* current = block_current + new_in_block_idx; ++m_number_objects_used; return current; }
int writeFile(fileHandleType fh, char *buffer, unsigned int size, securityIdType securityID) { unsigned int leftToWrite; unsigned int writePtr; unsigned int blockOffset; unsigned int writePos; unsigned char *blockBuffer; unsigned int blockSize; void *blockForWrite; unsigned int blockNumForWrite; unsigned int remainingBlockSpace; unsigned int dirEntry; unsigned int *catalogBlock; unsigned int blockIndexForWrite; int retval; int writeLength; char tmpbuffer[32]; int retcode; if (fh > MAX_OPEN_FILES) { return ERROR_BAD_HANDLE; } if (fileCursors[fh].inUse == 0) { return ERROR_BAD_HANDLE; } if (buffer == 0) { return ERROR_BAD_VALUE; } if (size == 0) { return ERROR_BAD_VALUE; } if ( (securityID != fileCursors[fh].securityID) && securityID != ROOT_ID && (fileCursors[fh].othersPermissions&0x01) == 0) { return ERROR_NO_PERMISSION; } // treat a memory file specially if (fileCursors[fh].fileType > 2 ) { retcode=writeMemoryFile( fh, buffer, size ); return retcode; } leftToWrite = size; writePos = fileCursors[fh].writePos; // get a local of the blocksize just to keep code more readable blockSize = masterBlocks->mblock0.blockSize; while(leftToWrite > 0) { blockOffset = writePos % blockSize; // if blockOffset is 0 then a new block for writing needs to be allocated, unless we // aren't at the end of the file if (blockOffset == 0 && writePos == fileCursors[fh].fileSize) { if (addNewBlock(fh) == -1) { return ERROR_NO_BLOCKS; } } // read block where writing will happen and go from there dirEntry = fileCursors[fh].dirEntryNum; // read the catalog for this file if (readBlock(rootDir->entry[dirEntry].firstCatalogBlock, (void **)&catalogBlock) != 0) { return ERROR_READ_ERROR; } blockNumForWrite = *(unsigned int *)(catalogBlock + (writePos / blockSize)); deallocate(catalogBlock, blockSize); writeLength = minimum(blockSize - blockOffset, leftToWrite); if (readBlock(blockNumForWrite, &blockForWrite)!=0) { return ERROR_READ_ERROR; } memcpy(blockForWrite+blockOffset, buffer, writeLength); writeBlock(blockForWrite, blockNumForWrite); // free the memory for the buffer deallocate(blockForWrite, blockSize); leftToWrite -= writeLength; fileCursors[fh].fileSize += writeLength - (fileCursors[fh].fileSize - writePos); writePos += writeLength; } fileCursors[fh].writePos = writePos; return NO_ERROR; }