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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!postnews.google.com!d1g2000hsg.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: memory management in Ada: tedious without GC? Date: Fri, 16 May 2008 13:42:15 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9f2c2db4-d6c1-4cdf-884c-5cbc26ac7701@d1g2000hsg.googlegroups.com> References: <4ddef8bf-b5b1-4d7e-b75b-386cd6c8402c@l17g2000pri.googlegroups.com> NNTP-Posting-Host: 85.1.243.72 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1210970536 29275 127.0.0.1 (16 May 2008 20:42:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 16 May 2008 20:42:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d1g2000hsg.googlegroups.com; posting-host=85.1.243.72; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:118 Date: 2008-05-16T13:42:15-07:00 List-Id: On 16 Maj, 19:44, "jhc0...@gmail.com" wrote: > As I understood from reading the Memory Management section of > Wikibooks on Ada, Ada's memory management facilities are roughly > equivalent to > > a. C++-like "new" Yes, you can do this in Ada. > b. C++-like "delete" Yes, you can do this in Ada, but it is discouraged by the awful syntax and actually rarely needed. > c. Java-like "finally" I don't see any equivalent to "finally" in Ada - and, as in C++, it is not needed, since a superior tool is available: RAII. > d. your implementation may or may not have GC Just as in C++. In practice and for portability it means: assume there is no GC. > Did I misunderstand? Actually, Ada and C++ are very similar in this regard and Java differs widely from these two. > To me, this seems much, much more error-prone and tedious that C++'s > RAII approach In Ada RAII is realized with controlled types. They are severely broken in that they are intrusive in the type hierarchy and they burn the whole budget for implementation inheritance, which is a big issue with the lack of multiple inheritance (controlled streams, anyone?) - these problems don't exist in C++ - but apart from that both Ada and C+ + represent a similar approach to resource management. You *can* have RAII-enabled files, database sessions, smart pointers, and so on. Note that Ada, even though provides the possibility to use RAII when designing types, does not benefit from it everywhere in its standard library. > where you almost never have to worry about deallocation > (i.e. "b" and "c" above), even in the presence of exceptions, unless > you have GC. > Besides, RAII applies to a bunch of other things, like > thread locks, database connections, files - not just memory. That's why GC should not stop you from worrying about resources (and if you still have to worry, then what's the fuss?). The above are resources, which are not correctly addressed by GC as you know it from Java. Compared to this, RAII is a more uniform framework for handling resources *in general* and both Ada and C++ support it. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com