[fpc-pascal] AnsiString address changed

Michael Van Canneyt michael at freepascal.org
Mon Mar 18 11:29:06 CET 2024



On Mon, 18 Mar 2024, Hairy Pixels via fpc-pascal wrote:

>
>
>> On Mar 18, 2024, at 3:27 PM, Hairy Pixels <genericptr at gmail.com> wrote:
>> 
>> Oh, it's a pointer to a pointer? I guess that explains how it can resize itself and not invalidate shared references, if those are even possible with AnsiString.
>
> Wait, that's totally wrong. :) @s is the address of the local variable of course. I didn't think before I did that. I just wanted the address of the AnsiString.
>
> That still doesn't explain how they resize though. There must be not be more than 1 reference to any AnsiString at a time.

Of course there must be, that's the whole point of copy-on-write.

As soon as one reference is changed, a copy is made if the reference count
is larget than 1, and this copy is changed.

Michael.


More information about the fpc-pascal mailing list