[fpc-pascal] How does TFPGMap key compare work?
Ryan Joseph
genericptr at gmail.com
Mon Apr 19 19:05:55 CEST 2021
I have a question I was just curious about. From what I can tell TFPGMap uses CompareByte to compare keys of arbitrary type, which is clever but how does this work for ShortStrings? I have tried to use this method myself and I find it always fails because short strings have garbage at the end and so even if you zero out the memory (which is allocated) a short string passed as a parameter to a function will have garbage and thus fail to compare. Any ideas how this works for TFPGMap then?
function TFPSMap.BinaryCompareKey(Key1, Key2: Pointer): Integer;
begin
Result := CompareByte(Key1^, Key2^, FKeySize);
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list