[Info-vax] String handling, was: Re: C... the only winning move is not to play...
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Sat Feb 15 07:48:38 EST 2014
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.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list