[Info-vax] String handling, was: Re: C... the only winning move is not to play...

David Froble davef at tsoft-inc.com
Sat Feb 15 09:00:29 EST 2014


Simon Clubley wrote:
> On 2014-02-14, David Froble <davef at tsoft-inc.com> wrote:
>> Basic supports various types of strings, dynamic, fixed length, 
>> constants, MAPs, and so forth.
>>
>> Yes, if you declare a static string, that's there, nothing more to do 
>> except move data in and out.
>>
>> A dynamic string, every time it's set, must determine whether the 
>> current storage can be used, and if not, (I'm guessing a bit here), 
>> deallocate the current storage and allocate new storage of the desired 
>> length.  I heard once that if the new string is smaller, it uses the 
>> same storage, but, I'm not sure then how it knows that the storage is 
>> longer than the current string.
>>
> 
> For comparison, Ada has a half-way datatype, between fixed length and
> fully dynamic strings, called Bounded_String in which space up to a
> maximum length is pre-allocated but it's otherwise treated as a
> dynamic string.
> 
> It's more efficient than a fully dynamic string, but at the expense of
> allocating the memory for the maximum string size up front.
> 
> The Bounded_String package specification is here:
> 
> https://www2.adacore.com/gap-static/GNAT_Book/html/aarm/AA-A-4-4.html
> 
> and a readable example comparing the three basic string handling options
> in Ada is here:
> 
> http://en.wikibooks.org/wiki/Ada_Programming/Strings
> 
>> I will observe that it would be rare to have string manipulation in a 
>> loop that executes thousands (or more) times.  But it can happen.
> 
> Have you ever written a parser ? :-)
> 
> Simon.
> 

Well, it depends upon your definition of a "parser".  Yes, I've done 
such.  And dynamic strings really shine doing such work.  In such 
applications, you're going to have to "do the work", and the easier it 
is to write the code, the less chance for errors.  But you'll still not 
normally be doing as many iterations as some numeric calculations.



More information about the Info-vax mailing list