comp.lang.ada
 help / color / mirror / Atom feed
* Yet another efficiency question - To_Lower
@ 1997-07-02  0:00 Dale Stanbrough
  1997-07-03  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dale Stanbrough @ 1997-07-02  0:00 UTC (permalink / raw)



I was wondering if the a procedure

   procedure To_Lower (Item : in out String);

would be any more efficient for performing To_Lower operations
than the equivalent function in Ada.Characters.Handling, for when
a string is modified in place, i.e.

   Some_String : String (1..Size);
	
   Some_String := Ada.Characters.Handling.To_Lower (Some_String);

My simple view of the implementation of the function would be that it
allocates space (heap? secondary stack?), copies the values from 
Some_String to the temporary, modifies the value, and then copies it
back. (I'm always concerned when I think I see cases of copies being
made for no good reason).

C's to_lower, of course, just does an in place modification of the
'string'.


Dale




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

* Re: Yet another efficiency question - To_Lower
  1997-07-02  0:00 Yet another efficiency question - To_Lower Dale Stanbrough
@ 1997-07-03  0:00 ` Matthew Heaney
  1997-07-04  0:00 ` Robert Dewar
  1997-07-11  0:00 ` Dale Stanbrough
  2 siblings, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 1997-07-03  0:00 UTC (permalink / raw)



In article <5pclke$203$1@goanna.cs.rmit.edu.au>, Dale Stanbrough
<dale@goanna.cs.rmit.edu.au> wrote:

>I was wondering if the a procedure
>
>   procedure To_Lower (Item : in out String);
>
>would be any more efficient for performing To_Lower operations
>than the equivalent function in Ada.Characters.Handling, for when
>a string is modified in place, i.e.
>
>   Some_String : String (1..Size);
>        
>   Some_String := Ada.Characters.Handling.To_Lower (Some_String);

It would seem that having procedure forms would have been a good idea; I
don't know why they were omitted, nor does the AARM say either.

However, I think you can do what you want using the procedure form of
Translate in package Ada.Strings.Fixed.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Yet another efficiency question - To_Lower
  1997-07-02  0:00 Yet another efficiency question - To_Lower Dale Stanbrough
  1997-07-03  0:00 ` Matthew Heaney
@ 1997-07-04  0:00 ` Robert Dewar
  1997-07-11  0:00 ` Dale Stanbrough
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-07-04  0:00 UTC (permalink / raw)



Dale asks

<<My simple view of the implementation of the function would be that it
allocates space (heap? secondary stack?), copies the values from
Some_String to the temporary, modifies the value, and then copies it
back. (I'm always concerned when I think I see cases of copies being
made for no good reason).
>>

Indeed, functions returning variable length results will alwqays be less
efficient than operating in place on an in out fixed length parameter
(fixed length for a particular call).





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

* Re: Yet another efficiency question - To_Lower
  1997-07-02  0:00 Yet another efficiency question - To_Lower Dale Stanbrough
  1997-07-03  0:00 ` Matthew Heaney
  1997-07-04  0:00 ` Robert Dewar
@ 1997-07-11  0:00 ` Dale Stanbrough
  1997-07-11  0:00   ` Matthew Heaney
  1997-07-15  0:00   ` Laurent Guerby
  2 siblings, 2 replies; 6+ messages in thread
From: Dale Stanbrough @ 1997-07-11  0:00 UTC (permalink / raw)



Robert Dewar writes:

"Indeed, functions returning variable length results will alwqays be less
 efficient than operating in place on an in out fixed length parameter
 (fixed length for a particular call)."

The Ada model for constructors is to have functions returning values.
The logical implication then is that this is less efficient than the
C++ in situ constructor model, no?


Dale




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

* Re: Yet another efficiency question - To_Lower
  1997-07-11  0:00 ` Dale Stanbrough
@ 1997-07-11  0:00   ` Matthew Heaney
  1997-07-15  0:00   ` Laurent Guerby
  1 sibling, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 1997-07-11  0:00 UTC (permalink / raw)



In article <5q4lnk$9m$1@goanna.cs.rmit.edu.au>, Dale Stanbrough
<dale@goanna.cs.rmit.EDU.AU> wrote:

>Robert Dewar writes:
>
>"Indeed, functions returning variable length results will alwqays be less
> efficient than operating in place on an in out fixed length parameter
> (fixed length for a particular call)."
>
>The Ada model for constructors is to have functions returning values.
>The logical implication then is that this is less efficient than the
>C++ in situ constructor model, no?

No - you didn't read Robert's post carefully enough.  He said functions
returning "variable length" results.  Functions that return constrained
subtypes are just as efficient as anything else.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Yet another efficiency question - To_Lower
  1997-07-11  0:00 ` Dale Stanbrough
  1997-07-11  0:00   ` Matthew Heaney
@ 1997-07-15  0:00   ` Laurent Guerby
  1 sibling, 0 replies; 6+ messages in thread
From: Laurent Guerby @ 1997-07-15  0:00 UTC (permalink / raw)



Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:
> Robert Dewar writes:
> "Indeed, functions returning variable length results will alwqays be less
>  efficient than operating in place on an in out fixed length parameter
>  (fixed length for a particular call)."
> 
> The Ada model for constructors is to have functions returning values.
> The logical implication then is that this is less efficient than the
> C++ in situ constructor model, no?

   I don't think C++ has function variable-length results, so you can
say it's more efficient in C++ if you want ;-).  C++ variable length
data structure must go to the heap (thus using the very efficient
malloc/free stuff, whereas in Ada they can also be on the stack (BTW,
goodbye memory management nightmares).

   Also note that for many kind of constructors, you may be able to
use Ada discriminated types (thus avoiding the need for any
constructor).


-- 
Laurent Guerby <guerby@gnat.com>, Team Ada.
   "Use the Source, Luke. The Source will be with you, always (GPL)."




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

end of thread, other threads:[~1997-07-15  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-02  0:00 Yet another efficiency question - To_Lower Dale Stanbrough
1997-07-03  0:00 ` Matthew Heaney
1997-07-04  0:00 ` Robert Dewar
1997-07-11  0:00 ` Dale Stanbrough
1997-07-11  0:00   ` Matthew Heaney
1997-07-15  0:00   ` Laurent Guerby

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