Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2001-05

String parameters, ansistrings

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

SVAA

Hello:

Show quoted text 5 lines
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.

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.

Regards
Santiago Amposta

Reply by email

Florian Klaempfl
to SVAA
you wrote 34 lines
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!):

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

Reply by email

SVAA

Hello:

>No, it doesn't copy it if you don't modify the string, believe me, I >implemented >the ansistrings in FPC. >

I will believe it , and think twice before opening my mouth ;-)

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 ...

I've done it: I don't have so strong faith ;-)

with var or const:
about 14'5 seconds

without
about 17 seconds

A little better, but no so great. Any way, as you say, it's a good style. that's my consolation

Regards
Santiago Amposta

Reply by email

Florian Klaempfl
to SVAA: Hello: If you don't declare as "const" not "var", it copies the string. It doesn't matter…
you wrote 14 lines
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.

Show quoted text 7 lines
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;

Reply by email