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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,3ef3e78eacf6f938 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!o15g2000yqm.googlegroups.com!not-for-mail From: Andrea Taverna Newsgroups: comp.lang.ada Subject: A few Ada questions Date: Thu, 23 Jul 2009 15:58:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 151.47.210.9 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1248389903 31704 127.0.0.1 (23 Jul 2009 22:58:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 23 Jul 2009 22:58:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o15g2000yqm.googlegroups.com; posting-host=151.47.210.9; posting-account=q_H03goAAABDwevycEkYzGRVjq5lpBVA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7298 Date: 2009-07-23T15:58:21-07:00 List-Id: I've got a few questions about Ada, generated from discussion . I apologize for my annoying newbieness :D On 18 Lug, 17:50, Ludovic Brenta wrote: > Andrea Taverna wrote: > > [...] > > > So I have considered these alternatives: FreePascal, Eiffel, Ada and > > Modula-3 [....] > > As for memory management (requirement 4), I heard there are different > > takes on the matter: > > =A0(a) Ada uses dynamic stack allocation a lot, and in a transparent wa= y, > > reducing the need of manual management (MM) > > =A0(b) Ada libraries adopt idioms that further simplifies MM issues > > =A0(c) Conservative garbage collectors such as Bohem's can be used with > > Ada, and they are supposed to work "better" with Ada than with unsafe > > languages such as C and C++ > > I have to add: > =A0 (d) controlled types allow you to control allocation and > deallocation without a garbage collector. > > > So can MM be said to be easier in Ada than in C? I hope Ada-ers will > > mercifully shed some light on the issue. > > Yes, MM is definitely easier in Ada than in C; my experience with > Java's garbage collector is that (a) you never learn to manage memory, > and (b) is is very easy to run out of memory and get the infamous > OutOfMemoryError. =A0That has never happened to me in Ada, simply > because Ada forces me to think about this problem. > > Another reason why Ada is easier than C is because you use pointers > only for what they were designed: dynamic allocation and > deallocation. =A0As a consequence, each time you introduce a pointer you > naturally think about memory management. =A0Contrast this to C where > simple parameter passing often requires pointers, and with Eiffel or > Java where everything is a pointer whether you like it or not. > So I took a deeper look at Ada, and if I'm not mistaken, the MM support in Ada boils down to 1) dynamic stack allocation 2) malloc/free with Unchecked_Allocation 3) Controlled types that allow you implement constructors and destructors 4) Storage pools. Apart from (1) and (4), (2) and (3) seem to provide the same functionality of corresponding C++ features, with the notable exception that (3) requires tagging the type (*). As for (4), I couldn't find a practical example of storage pools usage on the net, I'd really like to see one. The storage pool I have in mind is the one used in ObjC/Cocoa, i.e. a storage pool with ref-counted objects. Users can send retain/release messages to increment/decrement the pool-allocated object's reference count. In which way does this differ from storage pools in Ada? I know that they have several benefits compared with pool-less storage, you can define a homogeneously typed/sized pool improving the memory management for associated types, and you can implement MM more easily, but, still, the problems I have with MM (at least in C) are : - application-specific code is intertwined with MM and vice versa. It complicates interfaces and hinders reusability. - objects have a graph-like relationship on which MM depends that could not be easy to foresee. - due to the graph relationship, refactoring MM code, which can ease MM itself, gets harder. How is Ada supposed to help with this? (*) besides, I infer that the visibility checks required for controlled types exposed at inner levels can be disabled at run-time, right? Finally, I'd have a question about the standard container library. I'm probably a bit confused since I've recently been hopping from a language to the other, but I saw that Containers do not define interfaces and Cursors types are not tagged. As such I'm not sure whether I can extend new containers from standard ones, including defining new cursors, while having polymorphic behaviour. For example, can I define a linked-list implemented with an array by deriving a standard container? thanks, Andrea