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,5a9bede4d09438a9 X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Unbounded array Date: 1999/04/29 Message-ID: <7g9qn5$g73$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 472297520 References: <37247AA2.116F5E00@wbkst21.mach.uni-karlsruhe.de> <7g23a9$k3k$1@nnrp1.dejanews.com> <37262C39.D4F16DD8@wbkst21.mach.uni-karlsruhe.de> X-Http-Proxy: 1.0 x7.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Apr 29 14:35:18 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I) Date: 1999-04-29T00:00:00+00:00 List-Id: In article , Matthew Heaney wrote: > Pawel Kobylarz writes: > > > Realloc function takes two parameters, the actual pointer and new > > size, and it preserves the data already present in the memory block. > > Realloc is more efficient than allocate-copy-deallocate, because it > > can add a piece of memory without moving existing data if there is > > place after the existing block. > > But that isn't guaranteed. You save the cost of a copy only if there's > an adjacent block large enough to contain the new part of the array. I wouldn't be suprised if it didn't *always* do the copy on some platforms. If if it does try to extend, unless the malloc algorithm is specificly optimized to leave holes for realloc, most of the time its probably going to have to copy anyway. > > In my textbook, I found only operators new and unchecked deallocation, > > nothing similar to realloc(). Is there in ADA something like > > realloc? > > No, it is not built in. However, you could > > 1) write a binding the C function It should be noted that if you do this, you should also write bindings to malloc or calloc and free, and you should use those calls rather than Ada's "new" and Unchecked_Deallocation. "new" is not guaranteed to be a straight call to malloc, so you could seriously hose things by trying to mix Ada and C allocations and deallocations. > > 2) write your own storage pool that supports a realloc-style operation, > and bind your access type to that pool; see RM95 13.11 That's probably the *best* solution. But of course it is also the most work and trickiest to implement correctly. Of course there's a third possibility: 3) Write a "Realloc (Ptr : in out ..." for your specific access type and do the "new", copy, and "Unchecked_Deallocation" in its body. If all Pawel was looking for was the convienence of doing that in one operation, this is probably the best way. -- T.E.D. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own