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-Thread: 103376,147f221051e5a63d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news1.google.com!news.glorb.com!transit3.readnews.com!transit4.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Fri, 16 May 2008 18:59:20 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: memory management in Ada: tedious without GC? References: <4ddef8bf-b5b1-4d7e-b75b-386cd6c8402c@l17g2000pri.googlegroups.com> <9f2c2db4-d6c1-4cdf-884c-5cbc26ac7701@d1g2000hsg.googlegroups.com> In-Reply-To: <9f2c2db4-d6c1-4cdf-884c-5cbc26ac7701@d1g2000hsg.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <482e11c6$0$11203$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: ff55bcde.news.sover.net X-Trace: DXC=]GLKjh^@VCSJiEbTeh[P]ZK6_LM2JZB_S56KDeg\4K@Z3?@`i3kGa5[QmVWlMd^f:RnKoP=O28l\P X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:129 Date: 2008-05-16T18:59:20-04:00 List-Id: Maciej Sobczak wrote: > In Ada RAII is realized with controlled types. Controlled types in Ada are great, but I think C++ has a bit of an edge in this area (not considering the issue of the type hierarchy). In Ada, the compiler calls Adjust after it has finalized the object on the left side of an assignment. In C++ operator=() has access to both sides of the assignment at once. This makes it easier to write exception safe assignment operators by copying the state of the source object *before* destroying the target. It doesn't seem like that's possible with Ada controlled types. I've worked around this by declaring such types limited, using Limited_Controlled, and living without a user defined assignment operation. This seems to be a feasible way to handle the situation, especially in Ada 2005 which allows functions to return limited types. Anyway, to the OP... yes, RAII is available in Ada although the precise details of how to set it up are a bit different than in C++. Be aware that Ada uses the word "finalize" differently than the way it is used in the Java community. In Ada finialization is more like C++ destruction. It is deterministic. Peter