void PoolSlab::destroy() { if (isSingleArray) for (unsigned NumPages = FirstUnused; NumPages != 1;--NumPages) FreePage((char*)this + (NumPages-1)*PageSize); FreePage(this); }
POSTINGSPTR treesearch_page_buildLL(int PageNo, char *key, struct node *root) { // ROOT, word POSTINGSPTR result; struct PageHdr *PagePtr = FetchPage(PageNo); if (PagePtr != NULL) { root = (struct node *) malloc(sizeof(struct node *)); root->value = PagePtr->PgNum; root->next = head; head = root; } if (IsLeaf(PagePtr)) { /* found leaf */ result = PageNo; head = root; } else if ((IsNonLeaf(PagePtr)) && (PagePtr->NumKeys == 0)) { /* keys, if any, will be stored in Page# 2 THESE PIECE OF CODE SHOULD GO soon! **/ result = treesearch_page_buildLL(FIRSTLEAFPG, key, root); } else if ((IsNonLeaf(PagePtr)) && (PagePtr->NumKeys > 0)) { PAGENO ChildPage = FindPageNumOfChild(PagePtr, PagePtr->KeyListPtr, key, PagePtr->NumKeys); result = treesearch_page_buildLL(ChildPage, key, root); } else { assert(0 && "this should never happen"); } FreePage(PagePtr); return result; }
UINT RenderCache::Paint(HDC hdc, RectI bounds, DisplayModel *dm, int pageNo, PageInfo *pageInfo, bool *renderOutOfDateCue) { assert(pageInfo->shown && 0.0 != pageInfo->visibleRatio); USHORT tileRes = GetTileRes(dm, pageNo); bool renderedReplacement; UINT renderTime = RENDER_DELAY_UNDEFINED, renderTimeMin = renderTime = RENDER_DELAY_UNDEFINED; for (int res = 0; res <= tileRes; res++) { renderedReplacement = false; renderTime = PaintTiles(hdc, bounds, dm, pageNo, pageInfo->pageOnScreen, res, res == tileRes, renderOutOfDateCue, &renderedReplacement); renderTimeMin = min(renderTime, renderTimeMin); } #ifdef CONSERVE_MEMORY if (0 == renderTime && !renderedReplacement) { // free tiles with different resolution TilePosition tile = { tileRes, -1, 0 }; FreePage(dm, pageNo, &tile); } #endif return renderTimeMin; }
void free_code(struct jit* jit, lua_State* L, cfunction func) { size_t i; struct jit_head* h = ((struct jit_head*) func) - 1; for (i = 0; i < jit->pagenum; i++) { struct page* p = jit->pages[i]; if ((uint8_t*) h < (uint8_t*) p || (uint8_t*) p + p->size <= (uint8_t*) h) { continue; } luaL_unref(L, LUA_REGISTRYINDEX, h->ref); EnableWrite(p, p->size); p->freed += h->size; shred(h, 0, h->size); if (p->freed < p->off) { EnableExecute(p, p->size); return; } FreePage(p, p->size); memmove(&jit->pages[i], &jit->pages[i+1], (jit->pagenum - (i+1)) * sizeof(jit->pages[0])); jit->pagenum--; return; } assert(!"couldn't find func in the jit pages"); }
void FreeDMA(DMAAddr addr, uint64_t size) { FreePage(addr.phys, size); Virtual::FreeVirtual(addr.virt, size); Virtual::UnmapRegion(addr.virt, size); // Log("freed DMA region: virt = %x, phys = %x, %d pages", addr.virt, addr.phys, size); }
/** * find the posting pointer to which the key should reside, given the * starting page number to look at. * * to search the whole tree, pass in ROOT as the page number. */ POSTINGSPTR treesearch(PAGENO PageNo, char *key) { /* recursive call to find page number */ const PAGENO page = treesearch_page(PageNo, key); /* from page number we traverse the leaf page */ struct PageHdr *PagePtr = FetchPage(page); POSTINGSPTR result = searchLeaf(PagePtr, key, 1); FreePage(PagePtr); return result; }
void MessageMemoryManager::FreeAll() { auto temp = m_pages; while(temp) { FreePage(temp); temp = temp->m_next; } }
UINT RenderCache::Paint(HDC hdc, RectI bounds, DisplayModel *dm, int pageNo, PageInfo *pageInfo, bool *renderOutOfDateCue) { assert(pageInfo->shown && 0.0 != pageInfo->visibleRatio); int rotation = dm->Rotation(); float zoom = dm->ZoomReal(); USHORT targetRes = GetTileRes(dm, pageNo); USHORT maxRes = GetMaxTileRes(dm, pageNo, rotation); if (maxRes < targetRes) maxRes = targetRes; Vec<TilePosition> queue; queue.Append(TilePosition(0, 0, 0)); UINT renderDelayMin = RENDER_DELAY_UNDEFINED; bool neededScaling = false; while (queue.Count() > 0) { TilePosition tile = queue.At(0); queue.RemoveAt(0); RectI tileOnScreen = GetTileOnScreen(dm->engine, pageNo, rotation, zoom, tile, pageInfo->pageOnScreen); tileOnScreen = pageInfo->pageOnScreen.Intersect(tileOnScreen); RectI isect = bounds.Intersect(tileOnScreen); if (isect.IsEmpty()) continue; bool isTargetRes = tile.res == targetRes; UINT renderDelay = PaintTile(hdc, isect, dm, pageNo, tile, tileOnScreen, isTargetRes, renderOutOfDateCue, isTargetRes ? &neededScaling : NULL); if (!(isTargetRes && 0 == renderDelay) && tile.res < maxRes) { queue.Append(TilePosition(tile.res + 1, tile.row * 2, tile.col * 2)); queue.Append(TilePosition(tile.res + 1, tile.row * 2, tile.col * 2 + 1)); queue.Append(TilePosition(tile.res + 1, tile.row * 2 + 1, tile.col * 2)); queue.Append(TilePosition(tile.res + 1, tile.row * 2 + 1, tile.col * 2 + 1)); } if (isTargetRes && renderDelay > 0) neededScaling = true; renderDelayMin = min(renderDelay, renderDelayMin); // paint tiles from left to right from top to bottom if (tile.res > 0 && queue.Count() > 0 && tile.res < queue.At(0).res) queue.Sort(cmpTilePosition); } #ifdef CONSERVE_MEMORY if (!neededScaling) { if (renderOutOfDateCue) *renderOutOfDateCue = false; // free tiles with different resolution TilePosition tile(targetRes, (USHORT)-1, 0); FreePage(dm, pageNo, &tile); } FreeNotVisible(); #endif return renderDelayMin; }
/* ================ idHeap::~idHeap returns all allocated memory back to OS ================ */ idHeap::~idHeap( void ) { idHeap::page_s *p; if ( smallCurPage ) { FreePage( smallCurPage ); // free small-heap current allocation page } p = smallFirstUsedPage; // free small-heap allocated pages while( p ) { idHeap::page_s *next = p->next; FreePage( p ); p= next; } p = largeFirstUsedPage; // free large-heap allocated pages while( p ) { idHeap::page_s *next = p->next; FreePage( p ); p = next; } p = mediumFirstFreePage; // free medium-heap allocated pages while( p ) { idHeap::page_s *next = p->next; FreePage( p ); p = next; } p = mediumFirstUsedPage; // free medium-heap allocated completely used pages while( p ) { idHeap::page_s *next = p->next; FreePage( p ); p = next; } ReleaseSwappedPages(); if ( defragBlock ) { free( defragBlock ); } assert( pagesAllocated == 0 ); }
// go back void CPageViewer_Back(CPageViewer_t *viewer, int level) { if (viewer->page == NULL) return; while (viewer->page->next && level--) { CPageViewer_page_t *page = viewer->page->next; FreePage(viewer->page); viewer->page = page; } }
void CPageViewer_Clear(CPageViewer_t *viewer) { CPageViewer_page_t *next; LeaveNavigationMode(viewer); // free all pages while (viewer->page) { next = viewer->page->next; FreePage(viewer->page); viewer->page = next; } // clear CPageViewer_Init(viewer); }
void FixedSizeAllocator::FreeAll(void) { // free all pages PageHeader *pageWalker = m_pageList; while (pageWalker) { PageHeader *currPage = pageWalker; pageWalker = pageWalker->Next; FreePage(currPage); } // release pointers m_pageList = nullptr; m_freeList = nullptr; // re-init stats m_numPages = 0; m_numBlocks = 0; m_numFreeBlocks = 0; }
/** * recursive call to find the page in which the key should reside * and return the page number (guaranteed to be a leaf page). */ PAGENO treesearch_page(PAGENO PageNo, char *key) { // ROOT, word PAGENO result; struct PageHdr *PagePtr = FetchPage(PageNo); /*if (PagePtr != NULL) { printf("\ntree search - pgnum:%ld", PagePtr->PgNum); }*/ if (IsLeaf(PagePtr)) { /* found leaf */ result = PageNo; } else if ((IsNonLeaf(PagePtr)) && (PagePtr->NumKeys == 0)) { /* keys, if any, will be stored in Page# 2 THESE PIECE OF CODE SHOULD GO soon! **/ result = treesearch_page(FIRSTLEAFPG, key); } else if ((IsNonLeaf(PagePtr)) && (PagePtr->NumKeys > 0)) { PAGENO ChildPage = FindPageNumOfChild(PagePtr, PagePtr->KeyListPtr, key, PagePtr->NumKeys); result = treesearch_page(ChildPage, key); } else { assert(0 && "this should never happen"); } FreePage(PagePtr); return result; }
void RenderCache::Add(PageRenderRequest &req, RenderedBitmap *bitmap) { ScopedCritSec scope(&cacheAccess); assert(req.dm); req.rotation = NormalizeRotation(req.rotation); assert(cacheCount <= MAX_BITMAPS_CACHED); /* It's possible there still is a cached bitmap with different zoom/rotation */ FreePage(req.dm, req.pageNo, &req.tile); if (cacheCount >= MAX_BITMAPS_CACHED) { // free an invisible page of the same DisplayModel ... for (int i = 0; i < cacheCount; i++) { if (cache[i]->dm == req.dm && !req.dm->PageVisibleNearby(cache[i]->pageNo)) { DropCacheEntry(cache[i]); cacheCount--; memmove(&cache[i], &cache[i + 1], (cacheCount - i) * sizeof(cache[0])); break; } } // ... or just the oldest cached page if (cacheCount >= MAX_BITMAPS_CACHED) { DropCacheEntry(cache[0]); cacheCount--; memmove(&cache[0], &cache[1], cacheCount * sizeof(cache[0])); } } // Copy the PageRenderRequest as it will be reused BitmapCacheEntry entry = { req.dm, req.pageNo, req.rotation, req.zoom, req.tile, bitmap, 1 }; cache[cacheCount] = (BitmapCacheEntry *)_memdup(&entry); assert(cache[cacheCount]); if (!cache[cacheCount]) delete bitmap; else cacheCount++; }
UINT RenderCache::Paint(HDC hdc, RectI bounds, DisplayModel* dm, int pageNo, PageInfo* pageInfo, bool* renderOutOfDateCue) { AssertCrash(pageInfo->shown && 0.0 != pageInfo->visibleRatio); if (!dm->ShouldCacheRendering(pageNo)) { int rotation = dm->GetRotation(); float zoom = dm->GetZoomReal(pageNo); bounds = pageInfo->pageOnScreen.Intersect(bounds); RectD area = bounds.Convert<double>(); area.Offset(-pageInfo->pageOnScreen.x, -pageInfo->pageOnScreen.y); area = dm->GetEngine()->Transform(area, pageNo, zoom, rotation, true); RenderedBitmap* bmp = dm->GetEngine()->RenderBitmap(pageNo, zoom, rotation, &area); bool success = bmp && bmp->GetBitmap() && bmp->StretchDIBits(hdc, bounds); delete bmp; return success ? 0 : RENDER_DELAY_FAILED; } int rotation = dm->GetRotation(); float zoom = dm->GetZoomReal(); USHORT targetRes = GetTileRes(dm, pageNo); USHORT maxRes = GetMaxTileRes(dm, pageNo, rotation); if (maxRes < targetRes) maxRes = targetRes; Vec<TilePosition> queue; queue.Append(TilePosition(0, 0, 0)); UINT renderDelayMin = RENDER_DELAY_UNDEFINED; bool neededScaling = false; while (queue.size() > 0) { TilePosition tile = queue.PopAt(0); RectI tileOnScreen = GetTileOnScreen(dm->GetEngine(), pageNo, rotation, zoom, tile, pageInfo->pageOnScreen); if (tileOnScreen.IsEmpty()) { // display an error message when only empty tiles should be drawn (i.e. on page loading errors) renderDelayMin = std::min(RENDER_DELAY_FAILED, renderDelayMin); continue; } tileOnScreen = pageInfo->pageOnScreen.Intersect(tileOnScreen); RectI isect = bounds.Intersect(tileOnScreen); if (isect.IsEmpty()) continue; bool isTargetRes = tile.res == targetRes; UINT renderDelay = PaintTile(hdc, isect, dm, pageNo, tile, tileOnScreen, isTargetRes, renderOutOfDateCue, isTargetRes ? &neededScaling : nullptr); if (!(isTargetRes && 0 == renderDelay) && tile.res < maxRes) { queue.Append(TilePosition(tile.res + 1, tile.row * 2, tile.col * 2)); queue.Append(TilePosition(tile.res + 1, tile.row * 2, tile.col * 2 + 1)); queue.Append(TilePosition(tile.res + 1, tile.row * 2 + 1, tile.col * 2)); queue.Append(TilePosition(tile.res + 1, tile.row * 2 + 1, tile.col * 2 + 1)); } if (isTargetRes && renderDelay > 0) neededScaling = true; renderDelayMin = std::min(renderDelay, renderDelayMin); // paint tiles from left to right from top to bottom if (tile.res > 0 && queue.size() > 0 && tile.res < queue.at(0).res) queue.Sort(cmpTilePosition); } #ifdef CONSERVE_MEMORY if (!neededScaling) { if (renderOutOfDateCue) *renderOutOfDateCue = false; // free tiles with different resolution TilePosition tile(targetRes, (USHORT)-1, 0); FreePage(dm, pageNo, &tile); } FreeNotVisible(); #endif return renderDelayMin; }
/* Free all bitmaps in the cache that are not visible. Returns TRUE if freed at least one item. */ bool RenderCache::FreeNotVisible() { return FreePage(); }
/* Free all bitmaps cached for a given <dm>. Returns TRUE if freed at least one item. */ bool RenderCache::FreeForDisplayModel(DisplayModel *dm) { return FreePage(dm); }
int get_successors(char *key, int k, char *result[]) { struct KeyRecord *KeyListTraverser; int i; PAGENO pg = treesearch_page(ROOT, key); // fetch the first page struct PageHdr *PagePtr = FetchPage(pg); btReadCount ++; // get the key list KeyListTraverser = PagePtr->KeyListPtr; //find the key in keylist, store the pointer while(KeyListTraverser != NULL) { if (strcmp(KeyListTraverser->StoredKey, key) == 0) { KeyListTraverser = KeyListTraverser->Next; break; } else if (strcmp(KeyListTraverser->StoredKey, key) > 0) { break; } KeyListTraverser = KeyListTraverser->Next; } // then iterate each page and keyList to print the keys int count = 0; while(count < k) { while(KeyListTraverser != NULL && count < k) { strcpy(result[count], KeyListTraverser->StoredKey); //result[count] = KeyListTraverser->StoredKey; //printKey(KeyListTraverser); count ++; KeyListTraverser = KeyListTraverser->Next; } if (count < k && PagePtr->PgNumOfNxtLfPg != NULLPAGENO) { FreePage(PagePtr); btReadCount++; PagePtr = FetchPage(PagePtr->PgNumOfNxtLfPg); //printf("the number of keys in this node: %d\n", PagePtr->NumKeys); KeyListTraverser = PagePtr->KeyListPtr; } } printf("found %d successors:\n", count); for (i = 0; i < count; ++i) { printf("%s\n", result[i]); } FreePage(PagePtr); return 0; }
//-------------------------------------------------------------------------- // Find a empty page in Space and return its pointer. First look at the // expected spot. If an empty or expired page is not found then search // thru the pages. If one cannot be found then void the oldest one. // // hashnum the number of the page that might be empty. // // return the space location // uchar FindNew(uchar hashnum) { ulong tm,otm; static uchar spot = 0; // spot pointer uchar t = 0xFF; uchar oldest,i; uchar freepg; // if current spot is empty then use that if (BitMap[spot] == 0xFF) t = spot; // not empty so first try and find an empty spot in bitmap else { // get the current time tm = msGettick(); // set the oldest time to the current spot otm = Space[spot].Tstamp; oldest = spot; // check to see if spot is void if (tm > Space[spot].Tstamp) { freepg = FreePage(spot); t = spot; } else { // loop through all of the bitmap for (i = 0; i < DEPTH; i++) { if (BitMap[i] == 0xFF) // check for empty { t = i; break; } else if (tm > Space[i].Tstamp) // check for expired { freepg = FreePage((uchar)i); t = i; break; } else if (Space[i].Tstamp < otm) // find oldest { otm = Space[i].Tstamp; oldest = i; } } // check to see if not found one if (i == DEPTH) { // free the current spot freepg = FreePage(oldest); t = oldest; } } } // set next spot to the current spot + 1 spot = (spot == (DEPTH-1)) ? 0 : spot + 1; // set the bitmap to say where the page is going BitMap[t] = hashnum; // return the space location return t; }
//-------------------------------------------------------------------------- // Search the hash cache to find the page discribed by the rom and page. // If it is found and it has not expired, then return its Space number // or 0xFF if it can not be found. 'mflag' is the memory section flag // where 0x00 is normal memory space and 0x80 is status memory space. // // portnum the port number of the port being used for the // 1-Wire Network. // SNum the serial number for the part that the read is // to be done on. // page the page to start looking // mflag the flag to compare in looking for the right page // time the expired time to check // buf the buffer of the page data // len the length of the data on the page // space_num the space number in the table for the data of the page // // return true if the page data was found // SMALLINT FindPage(int portnum, uchar *SNum, PAGE_TYPE *page, uchar mflag, uchar time, uchar *buf, int *len, uchar *space_num) { static uchar DidInit=0; uchar hs,ptr=0xFF; short i=0; ulong tm; // initialize the file page cache (DSS 3.11) automatically if (!DidInit) { InitDHash(); DidInit = 1; } hs = HashFunction(SNum,*page); // if not empty if (Hash[hs] != 0xFF) { // get the current time tm = msGettick(); ptr = Hash[hs]; // point to first at hash spot do { // check to see if this record is expired if (time) { if (tm > Space[ptr].Tstamp) { ptr = FreePage(ptr); continue; // skip to loop check } } // check to see if this page is the correct one (and correct mem space) if ((Space[ptr].Page == *page) && (mflag == (Space[ptr].Data[0] & 0x80))) { for (i = 0; i < 8; i++) if (Space[ptr].ROM[i] != SNum[i]) break; if (i == 8) break; } // point to next page at hash location ptr = Space[ptr].Fptr; } while (ptr != 0xFF); } // check if need to copy over the data if (ptr != 0xFF) { if ((Space[ptr].Data[0] & 0x1F) <= 0x1D) { *len = Space[ptr].Data[0]; for (i = 1; i <= (*len & 0x1F); i++) buf[i-1] = Space[ptr].Data[i]; } else ptr = 0xFF; } // check result if(ptr == 0xFF) return FALSE; *space_num = ptr; return TRUE; }
int dfs(char *key, char* result[],PAGENO pgnum,int need, int k){ if(need<=0) return 0; struct PageHdr *PagePtr=FetchPage(pgnum); char *Word; /* Key stored in B-Tree */ struct KeyRecord* KeyListTraverser=PagePtr->KeyListPtr; /* put keyrecord into stack*/ int cmp_result; int NumKeys=PagePtr->NumKeys; int count=0; /*stack is only used for nonleaf pages*/ Stack* stack; if (IsLeaf(PagePtr)){ while (KeyListTraverser != NULL) { if(CompareKeys(KeyListTraverser->StoredKey,key)==0){ exist=1; break; } /*write this string into result. start from an empty place and, if get more string than needed, replace the oldest one*/ strcpy(result[count%need+k-need],KeyListTraverser->StoredKey); count++; KeyListTraverser = KeyListTraverser->Next; } FreePage(PagePtr); if( exist==0) return k; if(count>need) return need; else return count; }else{ /*Use stack to do backtrack and keep searching predecessor leaf pages*/ stack=init_stack(NumKeys+1); while( NumKeys>0){ Word=KeyListTraverser->StoredKey; (*(Word + KeyListTraverser->KeyLen)) = '\0'; cmp_result=CompareKeys(key, Word); NumKeys--; if(cmp_result<2){ /*put PAGENO into stack*/ push(stack,KeyListTraverser->PgNum); break; } /* put PAGENO into stack*/ push(stack,KeyListTraverser->PgNum); KeyListTraverser = KeyListTraverser->Next; } /* Because PgNum means the left side(remember for B+ tree Child node is on left side of one key record) child page no. This case means there are more beyond these left childs, which is the rightmost child of the parent */ if(cmp_result==2 && NumKeys==0){ push(stack,PagePtr->PtrToFinalRtgPg); } while(stack->top>0){ PAGENO tovisit= *(pop(stack)); count+= dfs(key,result,tovisit,need-count,k); if(count>=need) return need; } free_stack(stack); FreePage(PagePtr); return count; } }