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,bae7ef2665942955 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-12 20:33:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!cyclone-sf.pbi.net!216.218.192.242!news.he.net!newsfeed1.easynews.com!easynews.com!easynews!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: containers and garbage collections. References: <2458809.CYNMQ0Kujp@linux1.krischik.com> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 13 Sep 2003 03:33:56 GMT NNTP-Posting-Host: 65.110.133.134 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1063424036 65.110.133.134 (Fri, 12 Sep 2003 20:33:56 PDT) NNTP-Posting-Date: Fri, 12 Sep 2003 20:33:56 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:42433 Date: 2003-09-13T03:33:56+00:00 List-Id: Martin Krischik writes: > Without garbage collection access types are pain in the bud. And when the > container library only stores "type element is private;" than one need to > use access types as element. This statement is not quite correct. It all depends on your level of abstraction. For example, a container for indefinite types can be declared this way: generic type Element_Type (<>) is private; package Queues is type Queue_Type is limited private; procedure Insert (Queue : in out Queue_Type; Item : in Element_Type); function Top (Queue : Queue_Type) return Element_Type; procedure Pop (Queue : in out Queue_Type); private type Element_Access is access Element_Type; type Node_Type; type Node_Access is access Node_Type; type Node_Type is record Element : Element_Access; Next : Node_Access; end record; type Queue_Type is limited record Top : Node_Access; end record; end Queues; Now Insert can be implemented like this: procedure Insert (Queue : in out Queue_Type; Item : in Element_Type) is Node : constant Node_Access := new Node_Type'(Element => new Element_Type'(Item), Next => null); begin ... end; To extract an item, you just do this: procedure Op (Q : in out QT) is E : ET := Top (Q); begin Pop (Q); end; >From the point of view of a user of the queue, the queue contains elements, of indefinite type Element_Type. Clearly, inside the queue, access types are used, but that is an implementation detail hidden from client. > I have proven that both options are possible > > I have implemented a garbage collected storrage pool for GNAT. > > I also have created containers for "type Element (<>) is abstract tagged > private;" and I belive "type Element is array (Index range <>) of Item;" is > possible as well (Enabling collection of Strings). Both can't be done with > C++ templates - so we should not take the all mighty STL as an example. Both of these containers are possible using the single declaration: generic type Element_Type (<>) is private; package GP is ...; You can instantiate GP using either of the types in your example. It's not clear why you made two separate containers, one for tagged types vs. another for array types, as a single container seems adequate.