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,ed6a891101ff4e06 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Freeing Pointers to classwide types Date: 1998/10/09 Message-ID: #1/1 X-Deja-AN: 399372776 Sender: matt@mheaney.ni.net References: <1ftmFTC69GA.191@samson.airnet.net> <360b26a1.41575272@SantaClara01.news.InterNex.Net> <6ugeu2$79u$1@nnrp1.dejanews.com> <360c4a70.29707515@SantaClara01.news.InterNex.Net> <6uifpt$e98$1@nnrp1.dejanews.com> <360d1380.165146@SantaClara01.news.InterNex.Net> <6ulj29$ne3$1@nnrp1.dejanews.com> <360e790d.241368@SantaClara01.news.InterNex.Net> <6umkl8$qbm$1@nnrp1.dejanews.com> <360f143c.39974468@SantaClara01.news.InterNex.Net> <6uo8mt$el9$1@nnrp1.dejanews.com> <360fc072.1728326@SantaClara01.news.InterNex.Net> <6uokru$lbi$1@uuneo.neosoft.com> <360fec6e.12989714@SantaClara01.news.InterNex.Net> <6upond$4lc$1@nnrp1.dejanews.com> <361126ef.4269711@SantaClara01.news.InterNex.Net> <36127a1c.276097@SantaClara01.news.InterNex.Net> <6uuo50$1pg$1@nnrp1.dejanews.com> <36131a1b.34896409@SantaClara01.news.InterNex.Net> <87iui4bs8c.fsf@zaphod.enst.fr> <3613a5b1.186262@SantaClara01.news.InterNex.Net> <6v15au$7t0$1@nnrp1.dejanews.com> <6vl63k$cj0$1@nnrp1.dejanews.com> NNTP-Posting-Date: Fri, 09 Oct 1998 08:03:14 PDT Newsgroups: comp.lang.ada Date: 1998-10-09T00:00:00+00:00 List-Id: dennison@telepath.com writes: > In article , > Matthew Heaney wrote: > > > I think the issue is, Should you use UD without also specifying a > > storage pool too? I would answer, No. It has been my experience that > > using the UD off-the-shelf is a recipe for disaster. > > > > Pardon my naivete', but how does a storage pool help the situation? > Problems I know of that can happen with manual deallocation are not > doing it when you should (leaks) and doing it too soon (dangling > pointers). > > I suppose it might help with the leak problem *if* the access type > doesn't happen to be declared at the package level, but that seems to > be pretty rare. What good does it do in the more typical situation? Sorry - I gave an imcomplete answer. You also need to create a controlled abstraction that does the allocation and deallocation. Typically, the deallocation would be done automatically in the Finalize operation. The allocation is either done automatically during initialization, or is a part of the work done by a constructor of some kind called by the user. Type Ada.Strings.Unbounded.Unbounded_String is a good example. The allocation is done when you call To_Unbounded_String, and the deallocation is done when the scope ends in which the object is declared. In another post, I gave an example of automatical allocation during Initialization. (It was to allocate an active iterator whose type was limited and unconstrained.) The storage pool is necessary if you want to precisely control the time and space behavior of allocation and deallocation. But of course the pool is hidden from the client of the (controlled) abstraction - the access type, the storage pool, the call of new, and the call of unchecked_deallocation, are all implementation details not available to the client.