FRAMEWORK/MemChain.hpp
//---------------------------------------------------------------------------
// Block`s allocated size has changed - Recalculate Empty list
Block`s allocated size has changed - Recalculate Empty list
Block ` s allocated size has changed - Recalculate Empty list
void UpdateBlkEmpty(SIZE_T OldSize)
{
 if(this->Size == OldSize)return;  
 if(this->Empty >= this->Size){this->Empty = 0; return;}   
 if(this->Size < OldSize)  
  {
   if(!this->Empty)return;   
   SEmpty* Curr = (SEmpty*)((UINT8*)this + this->Empty);
   while(Curr->Next && (Curr->Next < this->Size))Curr = (SEmpty*)((UINT8*)this + Curr->Next);  
   Curr->Next = 0;  
   return;
  }
 UINT PIdx = (OldSize / MPageSize) + (bool)(OldSize % MPageSize);   
 SIZE_T COffs = PIdx * MPageSize; 
 this->MakeBlkEmpty(PIdx, true);
 if(this->Empty)
  {
   SEmpty* Curr = (SEmpty*)((UINT8*)this + this->Empty);
   while(Curr->Next)Curr = (SEmpty*)((UINT8*)this + Curr->Next);  
   Curr->Next = COffs + ((SMemPage*)((UINT8*)this + COffs))->HdrSize; 
  }
   else this->Empty = COffs + ((SMemPage*)((UINT8*)this + COffs))->HdrSize;
}
void UpdateBlkEmpty ( SIZE_T OldSize ) { if ( this -> Size == OldSize ) return ; if ( this -> Empty >= this -> Size ) { this -> Empty = 0 ; return ; } if ( this -> Size < OldSize ) { if ( ! this -> Empty ) return ; SEmpty * Curr = ( SEmpty * ) ( ( UINT8 * ) this + this -> Empty ) ; while ( Curr -> Next && ( Curr -> Next < this -> Size ) ) Curr = ( SEmpty * ) ( ( UINT8 * ) this + Curr -> Next ) ; Curr -> Next = 0 ; return ; } UINT PIdx = ( OldSize / MPageSize ) + ( bool ) ( OldSize % MPageSize ) ; SIZE_T COffs = PIdx * MPageSize ; this -> MakeBlkEmpty ( PIdx , true ) ; if ( this -> Empty ) { SEmpty * Curr = ( SEmpty * ) ( ( UINT8 * ) this + this -> Empty ) ; while ( Curr -> Next ) Curr = ( SEmpty * ) ( ( UINT8 * ) this + Curr -> Next ) ; Curr -> Next = COffs + ( ( SMemPage * ) ( ( UINT8 * ) this + COffs ) ) -> HdrSize ; } else this -> Empty = COffs + ( ( SMemPage * ) ( ( UINT8 * ) this + COffs ) ) -> HdrSize ; }
Block`s allocated size has changed - Recalculate Empty list
Block ` s allocated size has changed - Recalculate Empty list
// Nothing changed // No empty left (Possibly after shrinking the block) // Shrinking - Trim Free list // No empty // Find last one // Make it Last one // Has Grown - Init new pages as Free // Find last one