[lazarus] String parameters, ansistrings

Florian Klaempfl Florian.Klaempfl at gmx.de
Sun May 20 16:37:07 EDT 2001


At 21:18 20.05.01 -0500, you wrote:
>Hello:
>
> >
> >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 
implemented
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!):

function a2(const s:string):integer;

var
    hs : ansistring;

begin
a2:=ord(s[1]);
end;








More information about the Lazarus mailing list