comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: 'others' - inefficient esp. DEC Ada? [1/1]
Date: 1997/10/15
Date: 1997-10-15T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680001510972250470001@news.ni.net> (raw)
In-Reply-To: +3g7rFB7dIQ0EwNI@RK-COMP.DEMON.CO.UK


In article <+3g7rFB7dIQ0EwNI@RK-COMP.DEMON.CO.UK>, Rob Kirkbride
<rob@rk-comp.demon.co.uk> wrote:


>While doing this study I was staggered to find that the 'others'
>construct when used to clear an error eg.
>My_Array := (others => Null_Element) can be 3-4 times SLOWER than
>using a loop eg.
>
>for My_Element in My_Array'range loop
>        My_Array (My_Element) := Null_Element;
>end loop;
>
>This is because using the 'others' the array is built up in another part
>of memory before being copied back to My_Array, apparently because
>Null_Element could be a function and it may raise a constraint error.

You can't declare a constant prior to doing the assignment? ie

declare
   Value : constant T := Null_Element;
begin
   My_Array := (others => Value);
end;

I don't really know if it would make any difference though.  

Did you try getting rid of others, and using O'Range? ie

declare
   Value : constant T := Null_Element;
begin
   My_Array := (My_Array'Range => Value);
end;

What about the array itself? Is it a static subtype?  Do you know up front
what the index constraint is?  ie

declare
   Value : constant T := Null_Element;
begin
   My_Array := (My_Array_Index_Subtype'Range => Value);
end;

Maybe if the array index subtype were static then the assignment would be
more efficient.

What's the performance constraint?  Is it the construction of the value of
the RHS, or is it the copy itself?  Perhaps you can build the value once,
and then copy it:

   Null_Element_Array : constant My_Array := (others => Null_Element);
   -- In a static scope...

...

   My_Array := Null_Element_Array;
   -- In a dynamic scope...

At least this would get rid of the overhead of the construction of the
value, as you do the construction once and keep reusing it.  You could even
put it on the heap if the Null_Element_Array length can change, and keep
reusing it until its length changes again.

These are all just wild guesses though.  Sometimes you just have to play
the lottery, eh?  Maybe you'll get lucky.

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




      parent reply	other threads:[~1997-10-15  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-12  0:00 'others' - inefficient esp. DEC Ada? [1/1] Rob Kirkbride
1997-10-13  0:00 ` Tom Moran
1997-10-12  0:00   ` Michael & Amy Hartsough
1997-10-13  0:00   ` Rob Kirkbride
1997-10-14  0:00 ` Jeff Creem
1997-10-15  0:00 ` Matthew Heaney [this message]
replies disabled

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