Changeset 2424 in vbox for trunk/src/VBox
- Timestamp:
- Apr 30, 2007 12:17:10 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/alloc/heapsimple.cpp
r1816 r2424 281 281 RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE pHeap, void *pvMemory, size_t cbMemory) 282 282 { 283 PRTHEAPSIMPLEINTERNAL pHeapInt; 284 PRTHEAPSIMPLEFREE pFree; 285 unsigned i; 286 283 287 /* 284 288 * Validate input. The imposed minimum heap size is just a convenien value. … … 292 296 * enforce 32 byte alignment of it. Also align the heap size correctly. 293 297 */ 294 PRTHEAPSIMPLEINTERNALpHeapInt = (PRTHEAPSIMPLEINTERNAL)pvMemory;298 pHeapInt = (PRTHEAPSIMPLEINTERNAL)pvMemory; 295 299 if ((uintptr_t)pvMemory & 31) 296 300 { … … 310 314 - sizeof(RTHEAPSIMPLEINTERNAL); 311 315 pHeapInt->pFreeTail = pHeapInt->pFreeHead = (PRTHEAPSIMPLEFREE)(pHeapInt + 1); 312 unsigned i;313 316 for (i = 0; i < ELEMENTS(pHeapInt->auAlignment); i++) 314 317 pHeapInt->auAlignment[i] = ~(size_t)0; 315 318 316 319 /* Init the single free block. */ 317 PRTHEAPSIMPLEFREEpFree = pHeapInt->pFreeHead;320 pFree = pHeapInt->pFreeHead; 318 321 pFree->Core.pNext = NULL; 319 322 pFree->Core.pPrev = NULL; … … 348 351 { 349 352 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 353 PRTHEAPSIMPLEBLOCK pBlock; 350 354 351 355 /* … … 370 374 * Do the allocation. 371 375 */ 372 PRTHEAPSIMPLEBLOCKpBlock = rtHeapSimpleAllocBlock(pHeapInt, cb, cbAlignment);376 pBlock = rtHeapSimpleAllocBlock(pHeapInt, cb, cbAlignment); 373 377 if (RT_LIKELY(pBlock)) 374 378 { … … 394 398 { 395 399 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 400 PRTHEAPSIMPLEBLOCK pBlock; 396 401 397 402 /* … … 416 421 * Do the allocation. 417 422 */ 418 PRTHEAPSIMPLEBLOCKpBlock = rtHeapSimpleAllocBlock(pHeapInt, cb, cbAlignment);423 pBlock = rtHeapSimpleAllocBlock(pHeapInt, cb, cbAlignment); 419 424 if (RT_LIKELY(pBlock)) 420 425 { … … 453 458 pFree = pFree->pNext) 454 459 { 460 uintptr_t offAlign; 455 461 ASSERT_BLOCK_FREE(pHeapInt, pFree); 456 462 … … 460 466 if (pFree->cb < cb) 461 467 continue; 462 uintptr_toffAlign = (uintptr_t)(&pFree->Core + 1) & (uAlignment - 1);468 offAlign = (uintptr_t)(&pFree->Core + 1) & (uAlignment - 1); 463 469 if (offAlign) 464 470 { 471 RTHEAPSIMPLEFREE Free; 472 PRTHEAPSIMPLEBLOCK pPrev; 473 465 474 offAlign = uAlignment - offAlign; 466 475 if (pFree->cb - offAlign < cb) … … 470 479 * Make a stack copy of the free block header and adjust the pointer. 471 480 */ 472 RTHEAPSIMPLEFREEFree = *pFree;481 Free = *pFree; 473 482 pFree = (PRTHEAPSIMPLEFREE)((uintptr_t)pFree + offAlign); 474 483 … … 482 491 * for that.) 483 492 */ 484 PRTHEAPSIMPLEBLOCKpPrev = Free.Core.pPrev;493 pPrev = Free.Core.pPrev; 485 494 if (pPrev) 486 495 { … … 606 615 RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE Heap, void *pv) 607 616 { 617 PRTHEAPSIMPLEINTERNAL pHeapInt; 618 PRTHEAPSIMPLEBLOCK pBlock; 619 608 620 /* 609 621 * Validate input. … … 617 629 * Get the block and heap. If in strict mode, validate these. 618 630 */ 619 PRTHEAPSIMPLEBLOCKpBlock = (PRTHEAPSIMPLEBLOCK)pv - 1;620 PRTHEAPSIMPLEINTERNALpHeapInt = pBlock->pHeap;631 pBlock = (PRTHEAPSIMPLEBLOCK)pv - 1; 632 pHeapInt = pBlock->pHeap; 621 633 ASSERT_BLOCK_USED(pHeapInt, pBlock); 622 634 ASSERT_ANCHOR(pHeapInt); … … 802 814 RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE Heap, void *pv) 803 815 { 816 PRTHEAPSIMPLEINTERNAL pHeapInt; 817 PRTHEAPSIMPLEBLOCK pBlock; 818 size_t cbBlock; 819 804 820 /* 805 821 * Validate input. … … 813 829 * Get the block and heap. If in strict mode, validate these. 814 830 */ 815 PRTHEAPSIMPLEBLOCKpBlock = (PRTHEAPSIMPLEBLOCK)pv - 1;816 PRTHEAPSIMPLEINTERNALpHeapInt = pBlock->pHeap;831 pBlock = (PRTHEAPSIMPLEBLOCK)pv - 1; 832 pHeapInt = pBlock->pHeap; 817 833 ASSERT_BLOCK_USED(pHeapInt, pBlock); 818 834 ASSERT_ANCHOR(pHeapInt); … … 822 838 * Calculate the block size. 823 839 */ 824 c onst size_t cbBlock = (pBlock->pNext ? (uintptr_t)pBlock->pNext : (uintptr_t)pHeapInt->pvEnd)825 840 cbBlock = (pBlock->pNext ? (uintptr_t)pBlock->pNext : (uintptr_t)pHeapInt->pvEnd) 841 - (uintptr_t)pBlock- sizeof(RTHEAPSIMPLEBLOCK); 826 842 return cbBlock; 827 843 } … … 841 857 RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE Heap) 842 858 { 859 PRTHEAPSIMPLEINTERNAL pHeapInt; 860 843 861 if (Heap == NIL_RTHEAPSIMPLE) 844 862 return 0; 845 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 863 864 pHeapInt = Heap; 846 865 AssertPtrReturn(pHeapInt, 0); 847 866 ASSERT_ANCHOR(pHeapInt); … … 862 881 RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE Heap) 863 882 { 883 PRTHEAPSIMPLEINTERNAL pHeapInt; 884 864 885 if (Heap == NIL_RTHEAPSIMPLE) 865 886 return 0; 866 PRTHEAPSIMPLEINTERNAL pHeapInt = Heap; 887 888 pHeapInt = Heap; 867 889 AssertPtrReturn(pHeapInt, 0); 868 890 ASSERT_ANCHOR(pHeapInt); … … 880 902 { 881 903 PRTHEAPSIMPLEINTERNAL pHeapInt = (PRTHEAPSIMPLEINTERNAL)Heap; 904 PRTHEAPSIMPLEFREE pBlock; 905 882 906 pfnPrintf("**** Dumping Heap %p - cbHeap=%zx cbFree=%zx ****\n", 883 907 Heap, pHeapInt->cbHeap, pHeapInt->cbFree); 884 908 885 PRTHEAPSIMPLEFREE pBlock;886 909 for (pBlock = (PRTHEAPSIMPLEFREE)(pHeapInt + 1); 887 910 pBlock;
Note:
See TracChangeset
for help on using the changeset viewer.