[lazarus] String parameters, ansistrings

Florian Klaempfl Florian.Klaempfl at gmx.de
Sun May 20 18:01:32 EDT 2001

At 22:50 20.05.01 +0200, you wrote:
>At 21:18 20.05.01 -0500, you wrote:
>> >
>> >I think it doesn't matter for lazarus, because lazarus is mainly using
>> >ansistrings
>> >and ansistring parameters are only a pointer.
>> >
>>If you don't declare as "const" not "var", it copies the string.
>>It doesn't
>>matter if the internal implementation of ansistring is a pointer, for you it
>>is a variable, and if you don't declare it a var parameter you expect that
>>when you modify it inside the rutine the caller value won't be modified, so
>>it must copy.
>No, it doesn't copy it if you don't modify the string, believe me, I 
>the ansistrings in FPC.
>>I've test it with ansistrings (using H+, and declaring explicit ansistring)
>>and the results are similar:
>>with "const" of "var":
>>      about 1 second
>>Without "const" nor "var":
>>      about 17 seconds.
>The reason is that in this particular test case the a2 and the a3 procedures
>doesn't need an exception frame.
>Try the following and you'll get nearly the same times (only the declaration
>is added!):

Nevertheless, the const is much better programming style, if the string 
haven't to be modified ...

More information about the Lazarus mailing list