During debugging, encountered a grievous documentation error:
Code:
function TChepersyMemoryManagerChunk.Alloc: pointer;
var
i, k: integer;
j: cardinal;
m: ptruint;
begin
i:= 0;
// the mask bits of non-valid indexes are pre-set to 1, see the constructor
for i:= 0 to High(f_AllocMask) do begin
m:= not f_AllocMask[i];
if m = 0 then continue;
// https://www.freepascal.org/docs-html/current/rtl/system/bsfdword.html
// incorrectly states that BsfDWord returns 255 if no bits are set
// while in fact it returns 0! (at least in fp 2.6.4 it does)
j:= {$ifdef cpu64}BsfQWord( {$else}BsfDWord( {$endif} m );
addlog(' i=%0, j=%1, k=%2, mask=%3',[i,j,k,pointer(f_AllocMask[i])]) ;
// if j < 255 then begin
k:= (i * 8 * sizeof(pointer)) + j;
Assert((k >= f_IdxLow) and (k <= f_IdxHigh)
, 'TChepersyMemoryManagerChunk.Alloc: index ' + IntToStr(k)
+ ' is out of bounds (' + IntToStr(f_IdxLow) + ','
+ IntToStr(f_IdxHigh) + ')');
Inc(f_AllocCount);
Dec(f_FreeCount);
if f_FreeCount = 0 then CpsMemoryManager.OnChunkBecomingFull(Self);
f_AllocMask[i]:= f_AllocMask[i] or (ptruint(1) shl j);
Exit(pointer(ptruint(Self) + ptruint(k) * f_Size));
// end;
end;
Die(MI_ERROR_PROGRAMMER_NO_BAKA, [
'TChepersyMemoryManagerChunk.Alloc algorithm fail']);
end;
..aaand I'd say this is more than just twitching:

YEEEE-HAW!
Bookmarks