But what about the reverse ? Imagine a text 'document' that contains lots of LF,CR characters in Windows style, and converting that to Unix single char model. Does FPC adjust the memory allocation for every delete() ?
When talking about strings (refcounted longstring, e.g. ansistring, also widestring / not shortstring) then memory reallocation is only part of it.
And while I don't know (and it may depend on the memory manager used (fpc's own vs cmem or other), it might well be, that the shorter memory is not "moved", and only the freed part at the end returned to the mem pool.
But Insert/delete may do more...
But there is another
as well as insert/delete
=> they all need to ensure the string has a refcount of 1 (as otherwise they need to trigger copy on write).
That too, has a cost.
So usually you want to do:
uniquestring(MyStr); // now it has a refcount of 1
pMyStr := PChar(MyStr);
//SetLength(MyStr, NewLen); // If you need more space
pMyStr[i-1] := '?'; // 0 based index // The pchar changes the content of MyStr
SetLength(MyStr, NewLen); // If you shortened it
And of course if you insert delete chars, then call "move()".