comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephe.Leake@nasa.gov>
Subject: Re: Strings Fixed, Bounded, and Counted. Performance Inquiry.
Date: 27 Oct 2003 14:31:23 -0500
Date: 2003-10-27T19:35:04+00:00	[thread overview]
Message-ID: <u4qxubhpw.fsf@nasa.gov> (raw)
In-Reply-To: pan.2003.10.27.19.21.16.837359.802@nospam.net

Freejack <user@nospam.net> writes:

> On Mon, 27 Oct 2003 12:18:48 -0500, Stephen Leake wrote:
> 
>  
> >> A bit more flexible than Fixed strings,
> > 
> > How?
> 
> It was my understanding(I could be wrong here) that a Fixed string is
> unmodifiable without access to functions provided in the package. A
> Counted string is modifiable outside the package provided functions and
> procedures. No?

If you mean an Ada Counted string, you get to define it. If that's
what you want, so be it.

I don't see why using "functions provided in the package" is a
problem; that's what they are for!

> >> a heck of a lot faster than Null terminated strings.
> > 
> > Depends on what you are doing. Copying the strings character by
> > character is the same speed for either construct. Block copy is faster
> > with a count on most machines. But most algorithms for processing
> > strings operate character by character, so it doesn't really matter.
> > 
> > Safety is another issue; with a count (or bounds) it is possible to
> > check array indices before fetching or storing.
> 
>  So essentially, with a Fixed string, I can have the compiler generate
> machine code to grab a block of length X, and shove it into an empty
> block of length Y if Y > X? 

With any Ada string, Fixed or not. Yes.

> All on one I/O procedure? (Thinking of the Linux "sendfile()" and
> "iovec()" functions here.) I really want to avoid character by
> character transfer when it's not necessary. 

Let the compiler worry about that.

> Also, if I can read the first element, and see that the string has
> twenty characters, I can have the program inline a procedure x/20
> times, rather than using a Counter and loop structure.

That's what 'Length is for. Or the Length function in the
Ada.Strings.* packages. They are all very fast functions; you should
not worry about how fast they are.

> >> I'm gonna write my own experimental package if nobody else has
> > 
> > Be sure you define _precisely_ what you want the package to do, and see
> > if Ada already has it, before you spend time implementing it.
>  
> I am definitely being specific in my package spec. You're right. Aside
> from a couple quirks of my own design, bounded strings do the right
> thing. As do Fixed Strings.
> 
> I'll keep playing with 'em and tell you what I come up with. Heh.

Ok, sounds good.

-- 
-- Stephe



  reply	other threads:[~2003-10-27 19:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-24 20:18 Strings Fixed, Bounded, and Counted. Performance Inquiry Freejack
2003-10-24 20:28 ` Marin David Condic
2003-10-25  0:46 ` Jeffrey Carter
2003-10-25 21:24   ` Marin David Condic
2003-10-27 17:18 ` Stephen Leake
2003-10-27 19:15   ` Freejack
2003-10-27 19:31     ` Stephen Leake [this message]
2003-11-02 10:42   ` Tarjei T. Jensen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox