[futurebasic] Re: [FB] String handling and true records

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2003 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Tue, 05 Aug 2003 20:34:00 +0200

Bernie Wylde wrote:
> Dear All,
> I've noticed that many of the experts here tend now to use gString$[0] = 
> 0, rather than gString$ = "" to set a string to null or change 
> mid-string characters with something like gString$[5] = _"w". I suspect 
> the reason for this is speed.
> A month or so ago, I took a look at the source code for Code Styler on 
> the CD and it's changed my whole coding style. For example, I now try to 
> use true records wherever possible, (I call them "Alain-style globals"), 
> but handling strings as above doesn't seem possible with true records.
> Example:
> begin record appRec
>     dim as handle    txtH
>     dim as str255     string
>     dim as boolean bool
>     'etc.
> end record
> dim gApp as appRec
> gApp.string[0] = 0
> fn AppendMsgParam(msg, @gApp.string[1])
> The compiler throws up an error for the penultimate line because it 
> thinks that gApp.string[0] refers to the zeroth element of an array 
> inside the record and, athough the last line doesn't produce a compile 
> error, I wouldn't expect it to work in the program.
> Changing the last line to
> fn AppendMsgParam(msg, @gApp.string + 1)
> is a simple fix and there probably wouldn't be any speed loss, but is 
> there a faster alternative to gApp.string = "" ?
> Bernie
> P.S. I've just had a thought - will poke @gApp.string,0 do the trick?


This is a case where you have to use the suffix type identifier.

Just do something like this:

gApp.string$[0] = 0

or whathever index you like to change and see if that works.

As a side note, the bracket syntax is faster for sure, but the gain in 
speed is relevant with intensive string manipulation. With a statement 
alone of course it is not possible to tell the difference. Note also, 
that the string handling in FB are already and particularly optimized.