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.4 required=5.0 tests=BAYES_00,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,51359402da60c472 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-01 07:21:08 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: DYNAMIC ADA TASK CREATION? Date: 1 Jul 2003 07:21:08 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0307010621.e1de68d@posting.google.com> References: <3EF0026E.2050309@attbi.com> <3EF0F57D.9060507@attbi.com> <3EF15A7C.4030901@attbi.com> <1ec946d1.0306271654.636c1373@posting.google.com> <3EFD42B5.2060707@attbi.com> <0gpvfv49qaa0b62ab5m0kg39kka66sis8t@4ax.com> <1ec946d1.0306300701.77505dcf@posting.google.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1057069268 11946 127.0.0.1 (1 Jul 2003 14:21:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 1 Jul 2003 14:21:08 GMT Xref: archiver1.google.com comp.lang.ada:39956 Date: 2003-07-01T14:21:08+00:00 List-Id: Dmitry A. Kazakov wrote in message news:... > > I thought the container has only pointers to instances which are > created by caller, but maybe I missed something. > > [ An advantage in having (<>) for Element is that it could then have > T'Class as actual. For example: > > type Operand is new Ada.Finalization.Limited_Controlled with private; > type Operand_Ptr is access all Operand'Class; > ... > package Argument_Stack is new Limited_Stack > (Element => Operand'Class, Pointer => Operand_Ptr); > ] Then we are comparing apples and oranges. The containers I was talking about are declared like this: generic type Element_Type is limited private; package Generic_Container is ...; Strictly speaking your container doesn't have elements -- it has pointers to elements. The model in Charles is that an element is a component of an internal node of storage, which is designated by an iterator. If you want an access object that designates the element, then you can use Generic_Element to convert ("dereference") the iterator to the access type. Your container seems to have two levels of indirection: a pointer to an internal node contains a pointer to the element. In Charles there is only a single level of indirection. http://home.earthlink.net/~matthewjheaney/charles/index.html Of course, there is still the problem of a container of elements of indefinite type T'Class, which your container more or less solves. There are at least a couple of ways to do that in Charles. One way is to use a nonlimited container of pointers: package T_Class_Lists is new Charles.Lists.Double.Unbounded (T_Class_Access); Insert (List, New_Item => new T'Class'(...), Before => I); This implies that you have to manually deallocate the items prior to destruction of the container object, which you can do easily enough by passing an instantiation of Unchecked_Deallocation as the generic actual to Generic_Modify_Element. If you want to automate the finalization of container elements then you can use an Access_Control object as the element of a limited list: package T_Class_Lists is new Charles.Lists.Double.Limited_Unbounded (Pointer_Type); where Pointer_Type is an instantiation of Charles.Access_Control. (That package is analogous to the auto_ptr in C++.) You'd do something like: Insert (List, Before => I, Iterator => J); declare P : Pointer_Type renames To_Access (J).all; begin Initialize (P, new T'Class'(...)); end; So now when you delete the item: Delete (List, Iterator => J); then Free will be invoked automatically as a side-effect of finalization of the Pointer_Type object. One of the things that is lacking in the C++ STL is that you can't use an auto_ptr as a container element. The limited containers in Charles were partly motivated by a desire to provide that ability. The syntax is admittedly heavy, but you can ease the pain as desired by creating a thin layer (either over just the insertion operations as in the example above, or over the entire container). If there is interest then perhaps we can generalize your original idea by creating another container form: generic type Element_Type (<>) is limited private; type Handle_Type is private; with procedure Finalize (Handle : in out Handle_Type) is <>; package Generic_Indefinite_Containers is type Container_Type is limited private; procedure Insert (Container : in out Container_Type; New_Item : in Handle_Type); ... end Generic_Indefinite_Containers; Of course we could be more specific, by using an access type directly as the handle: generic type Element_Type (<>) is limited private; type Element_Access is access all Element_Type; with procedure Free (X : in out Element_Access) is <>; package Generic_Indefinite_Containers is ...; It would be trivial to implement either of these as a thin layer over the existing components in Charles, which is largely why I haven't bothered creating a separate component for indefinite types.