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,6148e77d4edcfadd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-23 15:36:33 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.newsreader.com!newsreader.com!newshosting.com!news-xfer1.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: freeing general access types User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Mon, 23 Dec 2002 23:35:37 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:32266 Date: 2002-12-23T23:35:37+00:00 List-Id: tmoran@acm.org writes: > If P is a general access type, is there any way to know whether it's > pointing to allocated storage, and should have Ada.Unchecked_Deallocation > applied to avoid a memory leak, or it's pointing at a declared > object, which should not be deallocated? No, other than whatever logic is in your program to keep track. Note that you also need to make sure you are deallocating from the right pool. If you have a value of a general access type, you do not generally know that it was allocated from the pool of that type. You must convert it to the right type before deallocating. I have written pool types where you can tell at run time which pool (if any) a given pointer is pointing into. But the more common thing is to encapsulate allocation and deallocation in a small place where you can understand (at compile time) what's going on. Many access types are not used for allocation/deallocation at all. They are used only for 'Access and/or conversion from other types. It's a good idea to write: for Acc_Type'Storage_Size use 0; for such types; then you will usually get a warning if you try to do a "new". And a run-time error. - Bob