Do I then get an intermediate state in which I have two copies of the 200 MB string? Do I have to worry about passing a Result.String string to the function so that I don't have to copy the string when the result is returned, thereby limiting the maximum string size due to memory constraints?
You have anyway at least two copies of the large string.
Space() needs 200 MB and when it is assigned to Result it needs another 200 MB of space.
And when I'm right, Space() do not release its memory to be faster when calling it again.
So during the return of the string from procedure you need 600 MB ...
PB uses a temp buffer where all string ops goes, so basically you need 3 times the space in this case (original string -> copied to temp buffer -> copied to new allocated buffer).
Fred wrote: Sat Jun 22, 2024 7:05 pm
Yes it's per thread, it get reduced automatically if the next operation doesn't need that much memory when the buffer is big.
It's good to know, as developers, something of how work is performed internally, as it can affect the way in which we approach solutions — thanks for that. Likewise to the OP for raising it too.