IndexNode IndexPage::newIndex(const char* key, int pageId, size_t cursor) { syncFlag = false; size_t size = IndexNode::getSize(key); // Create from free space if (freeSpace() >= size) { IndexNode rec(*this, indexStartPos + indexSpace()); rec.init(key, pageId, cursor); setIndexCount(indexCount() + 1); setIndexSpace(indexSpace() + size); setFreeSpace(freeSpace() - size); return rec; } // Check free node list try { IndexNode rec = freeList->findIndex(size); freeList->shrinkIndex(rec, size); // Init record rec.init(key, pageId, cursor); return rec; } catch (ReachLastIndex) { error("No space for new record"); return IndexNode(*this, 0); // Aviod Warning } }
Cmod<type>& Cmod<type>::operator=(const Cmod &other) { if (this == &other) return *this; zMStar = other.zMStar; // Yes, really copy this pointer q = other.q; m_inv = other.m_inv; context = other.context; zz_pBak bak; bak.save(); // backup the current modulus context.restore(); // Set NTL's current modulus to q root = other.root; rInv = other.rInv; powers_aux = other.powers_aux; ipowers_aux = other.ipowers_aux; Rb_aux = other.Rb_aux; iRb_aux = other.iRb_aux; // copy data, not pointers in these fields freeSpace(); // just in case if (other.powers) powers = new zpx(*(other.powers)); if (other.Rb) Rb = new fftrep(*(other.Rb)); if (other.Ra) Ra = new fftrep(*(other.Ra)); if (other.ipowers) ipowers = new zpx(*(other.ipowers)); if (other.iRb) iRb = new fftrep(*(other.iRb)); if (other.phimx) phimx = new zpxModulus(*(other.phimx)); if (other.scratch) scratch = new zpx(*(other.scratch)); return *this; }
bool IndexPage::hasSpace(size_t size) { if (freeSpace() >= size) return true; return freeList->hasSpace(size); }
size_type DataPage::addSingleRecord(const RecordId& recordId, const AddedValueRef& valueRef) { const size_type valueInlineSize = static_cast<size_type>(valueRef.value().size()); const size_type recordInlineSize = recordId.recordOverheadSize() + valueInlineSize; // record overhead (record id size + inline value size (2)) + value or large value reference. const bool canAdd = freeSpace() >= sizeof(uint16_t) + recordId.recordOverheadSize() + valueInlineSize; // record pointer (2) + record. if (canAdd) { // Compute offsets. const size_type endOfFreeArea = getEndOfFreeArea(); const size_type keyOffset = endOfFreeArea - recordInlineSize; const size_type valueOffset = endOfFreeArea - valueInlineSize; const size_type valueSizeOffset = valueOffset - sizeof(uint16_t); // Copy the key, value size and value. putBytes(keyOffset, recordId.value()); const uint16_t valueSizeOrTag = valueRef.valueSizeOrTag(); this->operator[](valueSizeOffset) = (valueSizeOrTag & 0xff); this->operator[](valueSizeOffset + 1) = ((valueSizeOrTag >> 8) & 0xff); const boost::string_ref value = valueRef.value(); putBytes(valueOffset, value); // Add new pointer to the start of the key. addRecordOffset(keyOffset); // Set new "end of free area". setEndOfFreeArea(keyOffset); } return (canAdd)? recordInlineSize : 0; }
void MemoryBundleStorage::store(const dtn::data::Bundle &bundle) { ibrcommon::MutexLock l(_bundleslock); if (_faulty) return; // get size of the bundle dtn::data::DefaultSerializer s(std::cout); dtn::data::Length size = s.getLength(bundle); // increment the storage size allocSpace(size); // insert Container pair<set<dtn::data::Bundle>::iterator,bool> ret = _bundles.insert( bundle ); if (ret.second) { const dtn::data::MetaBundle m = dtn::data::MetaBundle::create(bundle); _list.add(m); _priority_index.insert(m); _bundle_lengths[m] = size; // raise bundle added event eventBundleAdded(m); } else { // free the previously allocated space freeSpace(size); IBRCOMMON_LOGGER_DEBUG_TAG(MemoryBundleStorage::TAG, 5) << "got bundle duplicate " << bundle.toString() << IBRCOMMON_LOGGER_ENDL; } }
void Cmod<zz,zp,zpx,zzv,fftrep,zpContext>::privateInit(const PAlgebra& zms, const zz& rt) { context.restore(); // set NTL's current modulus zmStar = &zms; q = zp::modulus(); root = rt; // First find a 2m-th root of unity modulo q, if not given if (IsZero(root)) { context.restore(); // Set the current modulus to q zp rtp; unsigned e = 2*getM(); FindPrimitiveRoot(rtp,e); if (IsZero(rtp)) // sanity check Error("Cmod::compRoots(): no 2m'th roots of unity mod q"); root = rep(rtp); } rInv = InvMod(root,q); // set rInv = root^{-1} mod q // allocate memory (current modulus was defined above) freeSpace(); // just in case powers = new zpx(); Rb = new fftrep(); ipowers = new zpx(); iRb = new fftrep(); }
int main(void) { readFile(); calculate(4000, 100000); /**Changeable T and trial values**/ writeFile(); freeSpace(); }
bool MM_VerboseBuffer::ensureCapacity(MM_EnvironmentBase *env, uintptr_t spaceNeeded) { MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(env->getOmrVM()); bool result = true; if(freeSpace() < spaceNeeded) { /* Not enough space in the current buffer - try to alloc a larger one and use that */ char *oldBuffer = _buffer; uintptr_t currentSize = this->currentSize(); uintptr_t newStringLength = currentSize + spaceNeeded; uintptr_t newSize = newStringLength + (newStringLength / 2); char* newBuffer = (char *) extensions->getForge()->allocate(newSize, MM_AllocationCategory::DIAGNOSTIC, OMR_GET_CALLSITE()); if(NULL == newBuffer) { result = false; } else { _buffer = newBuffer; /* Got a new buffer - initialize it */ _bufferTop = _buffer + newSize; reset(); /* Copy across the contents of the old buffer */ strcpy(_buffer, oldBuffer); _bufferAlloc += currentSize; /* Delete the old buffer */ extensions->getForge()->free(oldBuffer); } } return result; }
void ParsedStream::getByte() { int c; if (_closed) { return; } if (freeSpace() == 0) { return; } // TODO: Tidy this... c = _uart->read(); if (c == -1) { return; } if (c == MATCH_TOKEN[bytes_matched]) { bytes_matched++; if (bytes_matched == strlen(MATCH_TOKEN)) { _closed = true; } } else if (c == MATCH_TOKEN[0]) { // Handle e.g. case "**CLOS*" bytes_matched = 1; } else { bytes_matched = 0; } storeByte(c); }
QString SystemConfig::flashInfo() { QString mount_point("/media/flash"); QString flash("%1/%2 MB"); flash=flash.arg(freeSpace(mount_point)/1024/1024).arg(diskSpace(mount_point)/1024/1024); return flash; }
/* * Can src be inserted in trg's area */ space* isNodeInsertable(node* src, node* trg) { space* s = getNodesSubSpace(trg); if( !isNodeInSpace(src, s) ){ freeSpace(s); return NULL; } return s; }
/** Assignment from a CoinPackedMatrix.*/ TMat & TMat::operator=(const CoinPackedMatrix &M){ freeSpace(); columnOrdering_.clear(); rowOrdering_.clear(); nnz_ = capacity_ = M.getNumElements(); create(M); return (*this); }
quint32 MemoryTablePrivate::allocate(quint32 size, TableMetadata *table, bool indexRequired) { const quint32 availableSpace = freeSpace(table); if (indexRequired) { // Even if satisfied from the free list, this allocation requires there to be space for expanded index if (availableSpace < sizeof(IndexElement)) { return 0; } } // Align the allocation so that the header is directly accessible quint32 allocationSize = static_cast<quint32>(requiredSpace(size)); allocationSize = roundUp(allocationSize, sizeof(quint32)); if (table->freeList) { // Try to reuse a freed block quint32 *bestOffset = 0; Allocation *bestBlock = 0; quint32 *freeOffset = &table->freeList; while (*freeOffset) { Allocation *freeBlock = allocationAt(*freeOffset, table); if (freeBlock->size >= allocationSize) { // This block is large enough if (!bestBlock || bestBlock->size > freeBlock->size) { // It's our best fit so far bestBlock = freeBlock; bestOffset = freeOffset; } } freeOffset = &freeBlock->nextOffset; } if (bestOffset) { // TODO: if this block is too large, should it be partitioned? quint32 rv = *bestOffset; *bestOffset = bestBlock->nextOffset; return rv; } } // Is there enough space for this allocation? if (availableSpace < (allocationSize + (indexRequired ? sizeof(IndexElement) : 0))) { return 0; } // Allocate the space immediately below the already-allocated space table->freeOffset -= allocationSize; Allocation *allocation = allocationAt(table->freeOffset, table); allocation->size = allocationSize; return table->freeOffset; }
/** Assignment operator (copy). * @param other is a reference to a list to be compared to this * @return true if the two lists are equal */ Dlist& Dlist::operator=(const Dlist& src) { if (this == &src) return *this; int old_n = n(); List::operator=(src); // copy parent class data if (n() != old_n) { // parent resized, do likewise freeSpace(); makeSpace(); } init(); for (index x = src.first(); x != 0; x = src.next(x)) pred[x] = src.pred[x]; return *this; }
void BaseContainer::saveConfiguration(KConfigGroup &group, bool layoutOnly) const { if(isImmutable()) { return; } // write positioning info group.writeEntry("FreeSpace2", freeSpace()); // write type specific info doSaveConfiguration(group, layoutOnly); }
void n_s_messageLender::c_messageUnit::operator=(const char *in) { clear(); unsigned int i=0; auto limit = freeSpace(); while( i < limit && in[i] != 0) { write_next_data((unsigned char)in[i]); i++; } }
int main() { int rows; int cols; int c; //scanf("%d %d\n", &rows, &cols); scanf("%d", &rows); scanf("%d", &cols); while ((c = getchar()) != '\n'); if(rows < 0 || cols < 0) //error check for senseless lengths of rows or columns { fprintf(stderr,"Error: Invalid number of columns or rows."); exit(2); } else { rows = rows + 2; //rows and cols incremented to add border around cols = cols + 2; int **table = makeTable(rows, cols); int tableFilled = fillTable(table, rows, cols); if(tableFilled == 0) { int **workTable = makeWorkTable(table, rows, cols); int temp = 1; if(findStartPos(table, workTable, rows, cols)) { fillTableWithPaths(workTable, rows, cols); temp = findEndPos(table, workTable, rows, cols); } if(temp == 0 || temp == 1) { int i, j; for(i = 1; i < rows - 1; i++) //print the maze with the path and without the border { for(j = 1; j < cols - 1; j++) { printf("%c", table[i][j]); } printf("%s", "\n"); } } freeSpace(table, workTable, rows); } else { fprintf(stderr,"Error: Invalid input with the specified rows and columns."); exit(2); } } return 0; }
bool MM_VerboseBuffer::vprintf(MM_EnvironmentBase *env, const char *format, va_list args) { OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary()); bool result = true; uintptr_t spaceFree = freeSpace(); va_list argsCopy; Assert_VGC_true('\0' == _bufferAlloc[0]); COPY_VA_LIST(argsCopy, args); uintptr_t spaceUsed = omrstr_vprintf(_bufferAlloc, spaceFree, format, argsCopy); /* account for the '\0' which isn't included in spaceUsed */ if ((spaceUsed + 1) < spaceFree) { /* the string fit in the buffer */ _bufferAlloc += spaceUsed; Assert_VGC_true('\0' == _bufferAlloc[0]); } else { /* undo anything that might have been written by the failed call to omrstr_vprintf */ _bufferAlloc[0] = '\0'; /* grow the buffer and try again */ COPY_VA_LIST(argsCopy, args); uintptr_t spaceNeeded = omrstr_vprintf(NULL, 0, format, argsCopy); if (ensureCapacity(env, spaceNeeded)) { COPY_VA_LIST(argsCopy, args); spaceUsed = omrstr_vprintf(_bufferAlloc, freeSpace(), format, argsCopy); Assert_VGC_true(spaceUsed < freeSpace()); _bufferAlloc += spaceUsed; Assert_VGC_true('\0' == _bufferAlloc[0]); } else { /* failed to expand buffer */ result = false; } } return result; }
uint32_t CursorWindow::alloc(size_t requestedSize, bool aligned) { int32_t size; uint32_t padding; if (aligned) { // 4 byte alignment padding = 4 - (mFreeOffset & 0x3); } else { padding = 0; } size = requestedSize + padding; if (size > freeSpace()) { LOGE("need to grow: mSize = %d, size = %d, freeSpace() = %d, numRows = %d", mSize, size, freeSpace(), mHeader->numRows); // Only grow the window if the first row doesn't fit if (mHeader->numRows > 1) { LOGE("not growing since there are already %d row(s), max size %d", mHeader->numRows, mMaxSize); return 0; } // Find a new size that will fit the allocation int allocated = mSize - freeSpace(); int newSize = mSize + WINDOW_ALLOCATION_SIZE; while (size > (newSize - allocated)) { newSize += WINDOW_ALLOCATION_SIZE; if (newSize > mMaxSize) { LOGE("Attempting to grow window beyond max size (%d)", mMaxSize); return 0; } } LOG_WINDOW("found size %d", newSize); mSize = newSize; } uint32_t offset = mFreeOffset + padding; mFreeOffset += size; return offset; }
void checkSpace(uint64_t const outlen) { // buffer overflow? if ( freeSpace() < outlen ) { flush(); assert ( opc == opa ); if ( outlen > outbuf.size() ) { ::libmaus::autoarray::AutoArray<uint8_t> newbuf(outlen); std::copy( outbuf.begin(), outbuf.end(), newbuf.begin() ); outbuf = newbuf; opa = outbuf.begin(); opc = opa; ope = outbuf.end(); } } assert ( freeSpace() >= outlen ); }
void WorldMap::drawAndUpdateCurrentScreen(sf::RenderWindow& mainWindow){ if (Static::toDelete.size() > 0){ freeSpace(gameMainVector,player->worldX,player->worldY); freeSpace(dungeonVector, player->worldX, player->worldY); freeSpace(secretRoomVector, player->worldX, player->worldY); //used when teleporting from one layer point to another layer differnet point such as triforce. freeSpace(gameMainVector, player->prevWorldX, player->prevWorldY); freeSpace(dungeonVector, player->prevWorldX, player->prevWorldY); freeSpace(secretRoomVector, player->prevWorldX, player->prevWorldY); } if(player->currentLayer==OverWorld){ if(player->movePlayerToNewVector) movePlayerToDifferentRoomVector(player->prevWorldX, player->prevWorldY, player->worldX, player->worldY); drawScreen(mainWindow, &gameBackgroundVector[player->worldX][player->worldY]); for(auto& obj : gameMainVector[player->worldX][player->worldY]) { if (!player->movePlayerToNewVector){ //if true the current vector may have changed mid loop since worldX/worldY //may be udpated(Teleport to Artifact room for example) //->unpredictable errors in other object update from previous vector. obj->update(&gameMainVector[player->worldX][player->worldY]); obj->draw(mainWindow); } } if (Static::toAdd.size()>0) addToGameVector(&gameMainVector[player->worldX][player->worldY]); } else if(player->currentLayer == InsideShop) { if(player->movePlayerToNewVector) movePlayerToDifferentRoomVector(player->prevWorldX, player->prevWorldY, player->worldX, player->worldY); drawScreen(mainWindow, &secretRoomBackgroundVector[player->worldX][player->worldY]); for(auto& obj : secretRoomVector[player->worldX][player->worldY]) { if (!player->movePlayerToNewVector){ obj->update(&secretRoomVector[player->worldX][player->worldY]); obj->draw(mainWindow); } } if (Static::toAdd.size()>0) addToGameVector(&secretRoomVector[player->worldX][player->worldY]); } else if(player->currentLayer == Dungeon) { if(player->movePlayerToNewVector) movePlayerToDifferentRoomVector(player->prevWorldX, player->prevWorldY, player->worldX, player->worldY); drawScreen(mainWindow, &dungeonBackgroundVector[player->worldX][player->worldY]); for(auto& obj : dungeonVector[player->worldX][player->worldY]) { if (!player->movePlayerToNewVector){ obj->update(&dungeonVector[player->worldX][player->worldY]); obj->draw(mainWindow); } } if (Static::toAdd.size()>0) addToGameVector(&dungeonVector[player->worldX][player->worldY]); } }
int LiquidContainerComponent::add(const QString &aLiquid, int aAmount) { if(!aAmount) return 0;//nothing to add if(liquid_.length() && liquid_ != aLiquid) return 0;//can't mix liquids int space = freeSpace(); if(space > aAmount) space = aAmount; amount_ += space; if(!liquid_.length()) liquid_ = aLiquid; return space; }
void setupSD() { //SdFat library only supports this if SD_SPI_CONFIGURATION is set to 1 in SdFatConfig.h SPI.setMOSI(sdMOSI); SPI.setMISO(sdMISO); SPI.setSCK(sdSCK); if (SD.begin(chipSelect)) { systemState.sdPresent = true; systemState.freeSpace = freeSpace(); } else { Serial.println("SD card initialization failed! SD will not be avaliable"); systemState.sdPresent = false; } }
StorageHandle PackedStorage::openForWriting(PageID page) { static bool wroteError=false; char filename[PATH_MAX]; getFilename(filename, sizeof(filename), page); //first try int desc=open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (desc != -1) { if (!seekTo(page, desc, true)) { ::close(desc); return StorageHandle(); } if ( maxBytes && byteCount>maxBytes ) freeSpace(); return (StorageHandle)desc; } //no space on disk? make some space available if (errno == ENOSPC) freeSpace(); //second try desc=open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (desc==-1 && !wroteError) { //report error to syslog - once! wroteError=true; esyslog("OSD-Teletext: Error opening teletext file %s: %s", filename, strerror(errno)); } if (desc==-1) return StorageHandle(); else if (!seekTo(page, desc, true)) { ::close(desc); return StorageHandle(); } if ( maxBytes && byteCount>maxBytes ) freeSpace(); return (StorageHandle)desc; }
uint8_t ParsedStream::available() { // NOTE: This causes a read/buffer fill which isn't entirely // consistent with how `available()` is normally // handled. // TODO: Put this buffer fill in the read section instead? // TODO: Don't refill if we're almost full and don't have a partial // match? while (!_closed && freeSpace() && _uart->available()) { getByte(); } return available(false); }
/** Assignment operator.*/ TMat& TMat::operator=(const TMat &rhs){ if(this != &rhs){ freeSpace(); nnz_ = rhs.nnz_; capacity_ = rhs.capacity_; iRow_ = CoinCopyOfArray(rhs.iRow_, rhs.nnz_); jCol_ = CoinCopyOfArray(rhs.jCol_, rhs.nnz_); value_ = CoinCopyOfArray(rhs.value_, rhs.nnz_); columnOrdering_ = rhs.columnOrdering_; rowOrdering_ = rhs.rowOrdering_; nonEmptyCols_.clear(); nonEmptyRows_.clear(); } return (*this); }
void MemoryBundleStorage::__erase(const bundle_list::iterator &iter) { const dtn::data::MetaBundle m = dtn::data::MetaBundle::create(*iter); // erase the bundle out of the priority index _priority_index.erase(m); // get the storage size of this bundle dtn::data::Length len = _bundle_lengths[m]; _bundle_lengths.erase(m); // decrement the storage size freeSpace(len); // remove bundle from bundle list _bundles.erase(iter); }
size_type DataPage::addSingleRecord(const boost::string_ref& recordInlineData) { const size_type recordInlineSize = static_cast<size_type>(recordInlineData.size()); const bool canAdd = freeSpace() >= sizeof(uint16_t) + recordInlineSize; if (canAdd) { // Compute offsets. const size_type endOfFreeArea = getEndOfFreeArea(); const size_type recordOffset = endOfFreeArea - recordInlineSize; // Copy the record, add pointer to its start and adjust "end of free area". putBytes(recordOffset, recordInlineData); addRecordOffset(recordOffset); setEndOfFreeArea(recordOffset); } return (canAdd)? recordInlineSize : 0; }
HBufC* CResourceLoader::ResolveSubStringDirsL(TDes& aText, TInt aCount, TBool* aMarker) { // Allocating heap buffer for return string. TInt destlength(aText.Length()); destlength = destlength + (KExtraSpaceForMainStringDirMarker) * aCount; HBufC* retbuf = HBufC::NewLC(destlength); TPtr retptr(retbuf->Des()); TInt freeSpace(destlength); TInt i(0); TInt j(0); TBuf<1> subsMarker; subsMarker.Append(KSubStringSeparator); TInt count(aCount - 1); while (i < aCount) { // Resolve sub string HBufC* buffer = ResolveSubStringL(aText, aMarker); TPtr ptr = buffer->Des(); CleanupStack::PushL(buffer); // Restore sub string separators if (freeSpace >= ptr.Length()) { retptr.Insert(j, ptr); freeSpace -= ptr.Length(); j += ptr.Length(); if (freeSpace > KExtraSpaceForMainStringDirMarker && i < count) { retptr.Append(subsMarker); j ++; } } CleanupStack::PopAndDestroy(buffer); i++; } retbuf = retbuf->ReAllocL(retptr.Length()); CleanupStack::Pop(); //retbuf return retbuf; }
uint32_t NativeCursorWindow::alloc(size_t size, bool aligned) { uint32_t padding; if (aligned) { // 4 byte alignment padding = (~mHeader->freeOffset + 1) & 3; } else { padding = 0; } uint32_t offset = mHeader->freeOffset + padding; uint32_t nextFreeOffset = offset + size; if (nextFreeOffset > mSize) { ALOGW("Window is full: requested allocation %d bytes, " "free space %d bytes, window size %d bytes", size, freeSpace(), mSize); return 0; } mHeader->freeOffset = nextFreeOffset; return offset; }