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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b1a1ed8b075945 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!d55g2000hsg.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Allocators and exceptions Date: Thu, 13 Sep 2007 02:43:41 -0700 Organization: http://groups.google.com Message-ID: <1189676621.912315.123470@d55g2000hsg.googlegroups.com> References: <1189323618.588340.87180@o80g2000hse.googlegroups.com> <1189369871.672082.162750@50g2000hsm.googlegroups.com> <1189460936.295604.143720@r29g2000hsg.googlegroups.com> <1189502377.626510.172690@22g2000hsm.googlegroups.com> <1189601170.835400.72630@w3g2000hsg.googlegroups.com> NNTP-Posting-Host: 137.138.37.241 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1189676622 13674 127.0.0.1 (13 Sep 2007 09:43:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Sep 2007 09:43:42 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070724 Red Hat/1.5.0.12-0.3.slc3 Firefox/1.5.0.12,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: d55g2000hsg.googlegroups.com; posting-host=137.138.37.241; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1940 Date: 2007-09-13T02:43:41-07:00 List-Id: On 13 Wrz, 00:32, "Randy Brukardt" wrote: > type Access_T is access all T; > procedure Free is new Unchecked_Deallocation (T, Access_T); > function Alloc_Object (...) return Access_T is > A_T : Access_T := new T; -- Default initialized. > begin > A_T.all := ; > return A_T; > exception > when others => Free(A_T); return null; > end Alloc_Object; Yes, this is a very reasonable approach. I would even propagate (or translate) the exception out instead of returning null - this can make it more plausible to work with at the call site. -- Maciej Sobczak http://www.msobczak.com/