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!news4.google.com!news.glorb.com!tsicnews.teliasonera.com!newsfeed.freenet.de!151.189.20.20.MISMATCH!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 15:21:32 +0200 Message-ID: NNTP-Posting-Date: 15 Apr 2005 15:21:32 MEST NNTP-Posting-Host: 53faf131.newsread2.arcor-online.net X-Trace: DXC=MbJ5P:7fh:=_78OXD477\?Q5U85hF6f;4jW\KbG]kaM8:cmYYm_h3\3I;0c7@T6oe:WRXZ37ga[7:n919Q4_`Vj9B8=X\UUgbk4 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10497 Date: 2005-04-15T15:21:32+02:00 List-Id: On Fri, 15 Apr 2005 11:49:23 GMT, Dr. Adrian Wrigley wrote: > On Fri, 15 Apr 2005 00:21:50 -0500, Randy Brukardt wrote: > >> My pool expands >> the arrays by rewriting the dope of the arrays passed into the functions - >> something that no one should ever do unless they're the author of the >> compiler. And probably not even then. > > I did this a lot a few years ago with GNAT. It worked extremely well. > (no I'm not the author of the compiler!) > > 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 ); - Element_Type is limited in the variant with 2 arguments and for an actual array of limited elements the implementation ensures that the result will not be moved in the address space. Otherwise Storage_Error is propagated. - For arrays of non-limited components the implementation is free to copy, adjust, finalize elements. - When Elements is negative the removed elements are properly finalized. - Storage_Error is propagated when the array wasn't re-sized as required, but X.all is valid. - Program_Error is propagated when X.all becomes invalid, for example after element's initialization/finalization exceptions. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de