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,be7fa91648ac3f12 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Large arrays (again), problem case for GNAT 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: Date: Fri, 15 Apr 2005 16:57:31 +0200 Message-ID: <1sul9x3f7m51j$.1202e03q30ehn$.dlg@40tude.net> NNTP-Posting-Date: 15 Apr 2005 16:57:31 MEST NNTP-Posting-Host: c1ce2d53.newsread4.arcor-online.net X-Trace: DXC=[Qd6oB9S54ga1IKbSTkC[i:ejgIfPPlddjW\KbG]kaMhZmYl>WOG@=eke:heMDRKNmWRXZ37ga[7jn919Q4_`VjiB8=X\UUgbkd X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10500 Date: 2005-04-15T16:57:31+02:00 List-Id: On Fri, 15 Apr 2005 14:31:30 GMT, Dr. Adrian Wrigley wrote: > On Fri, 15 Apr 2005 15:21:32 +0200, Dmitry A. Kazakov wrote: > >> On Fri, 15 Apr 2005 11:49:23 GMT, Dr. Adrian Wrigley wrote: >> > ... >>> I couldn't understand why there was no decent mechanism for changing >>> the size of an array. The resulting code was much cleaner, faster >>> and more memory efficient than using fancy data structures/container >>> libraries. >>> >>> Why did the language not provide an equivalent of 'realloc' for >>> arrays? >> >> I would propose: >> >> generic >> type Element_Type is limited private; >> type Index_Type is (<>); >> type Array_Type is array (Index_Type) of Element_Type; >> type Access_Type is access Array_Type; >> procedure Ada.Array_Resize (X : in out Access_Type; Elements : Integer); >> >> and >> >> generic >> type Element_Type is private; >> type Index_Type is (<>); >> type Array_Type is array (Index_Type) of Element_Type; >> type Access_Type is access Array_Type; >> procedure Ada.Array_Expand >> ( X : in out Access_Type; >> Elements : Natural; >> Initial : Element_Type >> ); > > This looks plausible. Could we specify the new 'Last index instead of > the Elements parameter? (what about a new 'First index?) Sounds interesting especially because "renames" handles it wrong. It might be very useful not to expand but just to adjust array view by moving 'First and 'Last. Typical case is: procedure Copy (X : in out My_Array; Y : in My_Array) is begin if X'Length /= Y'Length then raise ...; Now I know that I can copy Y to X, but I cannot synchronize their views to avoid range checks, clumsy I - X'First + Y'First and headache about possible overflows in the index expressions. > Maybe you'd > have difficulty creating a zero element array though. > > It'd be nice if it was less verbose too. 'new' seems so simple > to use - something equally simple would be nice for resizing. > Maybe an extra parameter for new or something(?) It isn't "new" it is a mixture of "renames", "new" and Unchecked_Deallocation. We could speculate about sugar like "with new" but what should be the right side: declare X : My_Array_Ptr := new My_Array (1..100_000); begin ... X := X with new (1..100_000 => 0.0); -- This is seems OK but what to do with arrays of limited elements? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de