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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,db88d0444fafe8eb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!easynet-monga!easynet.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Surprise in array concatenation Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1125610942.747981.280770@f14g2000cwb.googlegroups.com> <1125935610.797293.40550@g43g2000cwa.googlegroups.com> <1125942434.046551.206180@f14g2000cwb.googlegroups.com> Date: Tue, 6 Sep 2005 10:24:54 +0200 Message-ID: NNTP-Posting-Date: 06 Sep 2005 10:24:30 MEST NNTP-Posting-Host: 540edacc.newsread2.arcor-online.net X-Trace: DXC=WA@4n?D9BSA]\I;0c7@T6oeZWRXZ37ga[7Zn919Q4_`VjYB8=X\UUgbkT X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:4467 Date: 2005-09-06T10:24:30+02:00 List-Id: On 05 Sep 2005 18:13:16 -0400, Robert A Duff wrote: > But the Ada rule is _certainly_ not the "most efficient"! > > If all Strings start at 1, then we reduce the size of the array dope by > 4 bytes. If the average String length in your program is, say, 20 > bytes, you're saving 4 bytes for every 24, or about 17% of the memory > use, which is substantial. Saving memory generally speed up programs > due to cache effects. > > It's really annoying to me that the compiler stores zillions of copies > of the number 1 in memory (one copy for each String object), just > because some oddball String _might_ start at other than 1. > > Furthermore, bounds checking would be much faster, because there would > be no need to load the lower-bound from memory. Memory loads are often > slow on modern machines. > > Furthermore, consider the code generated for 'Length: In Ada, it's > something like: > > if X'First <= X'Last then > X'Last - X'First + 1 > else > 0 > end if; > > If X'First were known to be always 1, it would be: > > X'Last > > If X'First were known to be always 17, it would be: > > X'Last - 16 > > These latter are branch-free code sequences. Branches are often slow on > modern machines. Right. Here is another example to the list: almost any binary operation on strings should do: J := B'First; for I in A'Range loop do something to A(I) with B(J); J := J + 1; -- Can this overflow at the end of loop? (:-)) end loop; or its equivalent. It would be much less pain if either A'First = B'First (for some arrays, as a part of the contract), or at least array renaming worked properly (could shift the bounds.) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de