comp.lang.ada
 help / color / mirror / Atom feed
* ada.strings.unbounded "free" and "String_Access"
@ 2000-03-07  0:00 Al Johnston
  2000-03-08  0:00 ` Nick Roberts
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Al Johnston @ 2000-03-07  0:00 UTC (permalink / raw)


I am new to ada95 and am porting our code from ada83 to 95.
We currently pass things all over the place using a type
similar to unbounded's string_access.  Regrettably the
code relied on the 'address of an object of that type
being an address... so our code is broken in a lot of
places.  I am looking at replacing a lot of the places
where we were using our own "access String" type with
this strange unbounded.unbounded_string type.

But  I was wondering...  why is the type "ada.strings.
unbounded.string_access" as well as a "free" routine
for this type, provided in the spec of unbounded.strings?

I cant find a way of getting anything from this package
that is of this type, much less having a need to free it.

What don't I know? (why are these two available?).

The closes I could come was the function
"to_String(Souce : Unbounded_String) return String"
But if I understand this stuff correctly, this function
returns a copy of the string by-value.  If I wanted
the results of this function to hang around I would
have to do a "new" own my own, and then these
two (other wise useless) things would be useful... but
the really don't have anything to do with the "public"
part of the package.... again, what don't I understand.

thanks.

-al





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-07  0:00 ada.strings.unbounded "free" and "String_Access" Al Johnston
  2000-03-08  0:00 ` Nick Roberts
@ 2000-03-08  0:00 ` Robert A Duff
  2000-03-09  0:00 ` Al Johnston
  2 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 2000-03-08  0:00 UTC (permalink / raw)


Al Johnston <sofeise@mindspring.com> writes:

> But  I was wondering...  why is the type "ada.strings.
> unbounded.string_access" as well as a "free" routine
> for this type, provided in the spec of unbounded.strings?

There's no very good reason.  I think somebody just wanted to have a
String_Access type lying around for convenience.  And Strings.Unbounded
seemed like as good a place as any to put it.

> I cant find a way of getting anything from this package
> that is of this type, much less having a need to free it.

You're right.  Nothing else in this package has anything to do with
String_Access.

- Bob




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-07  0:00 ada.strings.unbounded "free" and "String_Access" Al Johnston
@ 2000-03-08  0:00 ` Nick Roberts
  2000-03-08  0:00   ` Jeff Carter
  2000-03-11  0:00   ` Robert A Duff
  2000-03-08  0:00 ` Robert A Duff
  2000-03-09  0:00 ` Al Johnston
  2 siblings, 2 replies; 8+ messages in thread
From: Nick Roberts @ 2000-03-08  0:00 UTC (permalink / raw)


The purpose is simply this: if Unbounded_String doesn't give you quite
enough flexibility in certain parts of your code (e.g. you need more speed),
you can use the type String_Access instead.

You may well employ the following strategy: convert value(s) of type
Unbounded_String to type String_Access (using the To_String function and the
'new' allocator); operate on the String_Access object(s) as required;
convert the result(s) back to type Unbounded_String (using the
To_Unbounded_String function).

This way, you can use the more encapsulated type Unbounded_String in most of
your code, and only use the lower-level String_Access type where you really
need to. The function Free is provided for you to explicitly deallocate the
String_Access object(s) if you want to (or need to).

Really, the type String_Access, and the function Free, are provided purely
as a convenience. They could easily have been omitted (to be declared
incidentally instead), but that was obviously felt to be just a little too
inconvenient by the designers of Ada 95 (and I agree with them).

--
Nick Roberts
http://www.adapower.com/lab/adaos

"Al Johnston" <sofeise@mindspring.com> wrote in message
news:38C5B5AD.D310C559@mindspring.com...
> ...
> But  I was wondering...  why is the type "ada.strings.
> unbounded.string_access" as well as a "free" routine
> for this type, provided in the spec of unbounded.strings?







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-08  0:00 ` Nick Roberts
@ 2000-03-08  0:00   ` Jeff Carter
  2000-03-10  0:00     ` Ted Dennison
  2000-03-11  0:00   ` Robert A Duff
  1 sibling, 1 reply; 8+ messages in thread
From: Jeff Carter @ 2000-03-08  0:00 UTC (permalink / raw)


Nick Roberts wrote:
> 
> The purpose is simply this: if Unbounded_String doesn't give you quite
> enough flexibility in certain parts of your code (e.g. you need more speed),
> you can use the type String_Access instead.
> 
> You may well employ the following strategy: convert value(s) of type
> Unbounded_String to type String_Access (using the To_String function and the
> 'new' allocator); operate on the String_Access object(s) as required;
> convert the result(s) back to type Unbounded_String (using the
> To_Unbounded_String function).

You don't need an access type for this (in Ada, you rarely need access
types at all). You can simply operate on the String returned by
To_String:

declare
   Value : [constant] String := To_String (Unbounded_Value);
begin
   -- Operate with/on Value
   Unbounded_Value := To_Unbounded_String (Value); -- if needed
end;

-- 
Jeff Carter
"You couldn't catch clap in a brothel, silly English K...niggets."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-07  0:00 ada.strings.unbounded "free" and "String_Access" Al Johnston
  2000-03-08  0:00 ` Nick Roberts
  2000-03-08  0:00 ` Robert A Duff
@ 2000-03-09  0:00 ` Al Johnston
  2 siblings, 0 replies; 8+ messages in thread
From: Al Johnston @ 2000-03-09  0:00 UTC (permalink / raw)


Thanks for clearing this up for me.  I wanted to make
sure I wasnt missing something here.

-al





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-08  0:00   ` Jeff Carter
@ 2000-03-10  0:00     ` Ted Dennison
  0 siblings, 0 replies; 8+ messages in thread
From: Ted Dennison @ 2000-03-10  0:00 UTC (permalink / raw)


In article <38C6D4DE.D482DA0C@acm.org>,
  jrcarter@acm.org wrote:
> Nick Roberts wrote:
> >
> > The purpose is simply this: if Unbounded_String doesn't give you
> > quite enough flexibility in certain parts of your code (e.g. you
> > need more speed), you can use the type String_Access instead.
> >

> You don't need an access type for this (in Ada, you rarely need access
> types at all). You can simply operate on the String returned by
> To_String:

You miss Nick's point. Doing that would cause the entire contents of the
string to get copied. For a somewhat longish string, passing the pointer
of the String_Access around instead would be significantly faster. I
just yesterday had to perform that very optimization in some code of
ours that is running at 60Hz with hard realtime performance
requirements.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-08  0:00 ` Nick Roberts
  2000-03-08  0:00   ` Jeff Carter
@ 2000-03-11  0:00   ` Robert A Duff
  2000-03-13  0:00     ` Robert Dewar
  1 sibling, 1 reply; 8+ messages in thread
From: Robert A Duff @ 2000-03-11  0:00 UTC (permalink / raw)


"Nick Roberts" <nickroberts@callnetuk.com> writes:

> Really, the type String_Access, and the function Free, are provided purely
> as a convenience. They could easily have been omitted (to be declared
> incidentally instead), but that was obviously felt to be just a little too
> inconvenient by the designers of Ada 95 (and I agree with them).

Right.  The inconvenience comes from the fact that you will end up with
several String_Access types in different packages (some probably called
String_Ptr, and so forth), and then when writing some code that uses
more than one package, you end up with a bunch of silly type
conversions.

If you always use the One True String_Access, you avoid that problem,
although that seems kind of kludgy if you don't really want to use
Unbounded_Strings.

- Bob




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ada.strings.unbounded "free" and "String_Access"
  2000-03-11  0:00   ` Robert A Duff
@ 2000-03-13  0:00     ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2000-03-13  0:00 UTC (permalink / raw)


In article <wccog8llcpu.fsf@world.std.com>,
  Robert A Duff <bobduff@world.std.com> wrote:
> Right.  The inconvenience comes from the fact that you will
end up with
> several String_Access types in different packages (some
probably called
> String_Ptr, and so forth), and then when writing some code
that uses
> more than one package, you end up with a bunch of silly type
> conversions.
>
> If you always use the One True String_Access, you avoid that
problem,
> although that seems kind of kludgy if you don't really want to
use
> Unbounded_Strings.


I really wanted to have a feature in Ada 95 to be able to refer
to a standard access type for any given type, perhaps something
like String'Access, but I could not generate enough enthusiasm
for this idea. As a result, you do indeed tend to get junk
access all over the place.

Note that there is a String_Access type just sitting there in
unbounded strings for no apparent purpose (it is not used
anywhere in the package). Perhaps the idea is that anyone
who needs a standard string access type should with this
(rather large) package?????



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-03-13  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-07  0:00 ada.strings.unbounded "free" and "String_Access" Al Johnston
2000-03-08  0:00 ` Nick Roberts
2000-03-08  0:00   ` Jeff Carter
2000-03-10  0:00     ` Ted Dennison
2000-03-11  0:00   ` Robert A Duff
2000-03-13  0:00     ` Robert Dewar
2000-03-08  0:00 ` Robert A Duff
2000-03-09  0:00 ` Al Johnston

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