FRAMEWORK/MemChain.hpp
//---------------------------------------------------------------------------
// Add each page to Empty chain
//
Add each page to Empty chain
Add each page to Empty chain
void MakeBlkEmpty(UINT32 PageIdx=0, bool InitHdrs=false)
{
 for(SIZE_T COffs = PageIdx*MPageSize;;)
  {
   SMemPage* MPage = (SMemPage*)((UINT8*)this + COffs);
   if(InitHdrs)         
    {
     if(COffs)     
      {
       MPage->HdrSize = MPage->HdrSize = AlignFrwrdPow2(sizeof(SMemPage<>), BAlignment);     
       MPage->PageIdx = COffs/MPageSize;
      } 
       else this->Empty = this->HdrSize;   
    }
   COffs += MPageSize;
   SEmpty* Curr = (SEmpty*)((UINT8*)MPage + MPage->HdrSize);
   Curr->Size = MPageSize - MPage->HdrSize;
   if(COffs >= this->Size){Curr->Next = 0; break;}  
     else Curr->Next = ((SMemPage*)((UINT8*)this + COffs))->HdrSize;  
  }
}
void MakeBlkEmpty ( UINT32 PageIdx = 0 , bool InitHdrs = false ) { for ( SIZE_T COffs = PageIdx * MPageSize ; ; ) { SMemPage * MPage = ( SMemPage * ) ( ( UINT8 * ) this + COffs ) ; if ( InitHdrs ) { if ( COffs ) { MPage -> HdrSize = MPage -> HdrSize = AlignFrwrdPow2 ( sizeof ( SMemPage < > ) , BAlignment ) ; MPage -> PageIdx = COffs / MPageSize ; } else this -> Empty = this -> HdrSize ; } COffs += MPageSize ; SEmpty * Curr = ( SEmpty * ) ( ( UINT8 * ) MPage + MPage -> HdrSize ) ; Curr -> Size = MPageSize - MPage -> HdrSize ; if ( COffs >= this -> Size ) { Curr -> Next = 0 ; break ; } else Curr -> Next = ( ( SMemPage * ) ( ( UINT8 * ) this + COffs ) ) -> HdrSize ; } }
Add each page to Empty chain
Add each page to Empty chain
// Done here to avoid passing data cache twice in a separete loops of InitHeaders and MakeBlkEmpty // Starting not from a first page // Align Page HeaderSize to specified aalignment(Helps to avoid page leftovers and growing Empty list when you allocating only objects of specific size) // From first block, init first header Empty ptr // No more pages // Point to a next page 