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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,71c743c03ed191fe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-18 17:43:49 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Beginer problem: variable array size Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Thu, 19 Sep 2002 00:43:11 GMT References: NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:29143 Date: 2002-09-19T00:43:11+00:00 List-Id: "Nacho" writes: > That does not resolve the problem. I need to change the size of the array > after it has been created. With your solution once array_called_p has been > created it will never change its size. Right. You've been admonished about considering the "proper Ada" way of allocating arrays local to a scope. You should consider those, but those require that the array size be known at the point of creation. There are many cases where you really need to change the size of an existing array (despite the admonishments that this is rare -- I think it's common). > The solution in c++ is easy as I posted before. Simply free the memory and > reserve new memory to hold the new size of the array. The solution is what Ludovic Brenta said: you do essentially the same as in C++ -- you deallocate and reallocate the array. And Pascal Obry gave good advice to encapsulate this in an abstraction. Look at the implementation of Ada.Strings.Unbounded, which is a size-changing array of characters. It's usually better to allocate exponentially-more space each time a reallocate-and-copy is needed. - Bob