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,e80a1497a689d8a5 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Ammo-zilla Date: 1999/10/24 Message-ID: <381324b9_1@news1.prserv.net>#1/1 X-Deja-AN: 539966630 Content-transfer-encoding: 7bit References: <38120FAF.945ADD7D@hso.link.com> <7uutgd$87h$1@nnrp1.deja.com> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 24 Oct 1999 15:24:41 GMT, 129.37.62.183 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-10-24T00:00:00+00:00 List-Id: In article <7uutgd$87h$1@nnrp1.deja.com> , Robert Dewar wrote: >> that there's a lot of memory leaks in it, which Ada is a lot better for. > > > Now that's an interesting comment, because to me C++ and Ada > are identical in this particular department, can you explain > why you think Ada is better wrt memory leaks? I can't speak for the original poster, but perhaps one reason is that functions in Ada can return unconstrained array types, eliminating the need to heap use, and therefore eliminating a source of memory leaks. I agree with Robert, but I'd go further and say that here C++ is superior to Ada95, because you can implement true "smart pointers" (by overriding the dereference operator "->") that reclaim memory automatically. You can do something very similar in Ada95 though, by wrapping the raw access object in a Controlled type and using unary plus to return the value. For example: type Bool_Exp is abstract tagged limited private; type Bool_Exp_Access is access all Bool_Exp'Class; -- Here's the smart pointer type: type Exp_Handle is private; function "+" (Handle : Exp_Handle) return Bool_Exp_Access; The article "Smart Pointers", in the patterns archive, describes the technique. (Use the search engine for find the word "smart" in the subject line.) Perhaps in a future version of the language controlled-ness (or some other form of garbage collection) can be applied to access types directly. For now, the smart pointer idiom isn't too much pain.