From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,213fbc70eb225c16 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: 'others' - inefficient esp. DEC Ada? [1/1] Date: 1997/10/15 Message-ID: #1/1 X-Deja-AN: 280910683 Distribution: world References: <+3g7rFB7dIQ0EwNI@RK-COMP.DEMON.CO.UK> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-10-15T00:00:00+00:00 List-Id: In article <+3g7rFB7dIQ0EwNI@RK-COMP.DEMON.CO.UK>, Rob Kirkbride 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 (818) 985-1271