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.2 required=5.0 tests=BAYES_00,HEADER_SPAM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b30bd69fa8f63cb2 X-Google-Attributes: gid103376,public X-Google-Thread: fc772,b30bd69fa8f63cb2 X-Google-Attributes: gidfc772,public X-Google-ArrivalTime: 2003-06-23 08:49:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: brangdon@cix.co.uk (Dave Harris) Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 23 Jun 2003 11:51:31 -0400 Organization: unknown Sender: cppmods@netlab.cs.rpi.edu Message-ID: References: Reply-To: brangdon@cix.co.uk NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: Mon, 23 Jun 2003 12:09 +0100 (BST) X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPvch/0HMCo9UcraBAQF1VQIAiMSD7QhMrZq5rGHLPhmsCcJuiGEqL/54 REArhBsv7EGZwufVwOsXQ9jOAlHDuudif7fT0/VSBEP+T2IUnJemWw== =6R3Q Xref: archiver1.google.com comp.lang.ada:39609 comp.lang.c++.moderated:68992 Date: 2003-06-23T11:51:31-04:00 List-Id: tslettebo@chello.no.nospam (=?Windows-1252?Q?Terje_Sletteb=F8?=) wrote (abridged): > > (GC is a big win when objects can be shared by pointers which are > > encapsulated. Then the question, "Has everyone finished with this > > object?" gets replaced by "Have I finished with this pointer?", > > which is a more local, encapsulated issue - fundamentally easier.) > > You get something similar with reference-counted smart pointers. Yes. Which have well-known problems with loops. Also, these introduce some of the issues you complain about for GC. For example, you may need weak pointers (eg boost has a weak pointer class). > > This would be a criticism of Java, not GC. Most GC languages have > > idioms to encapsulate stack-based cleanup. (These are often based > > on closures.) RAII is only "usual" in C++. > > In what way does this differ from RAII in C++. Could you give an example > from one of those languages? In Smalltalk: File open: 'filename' do: [:file| "use file" ] The stuff in square brackets is a block closure. #open:do: is a message sent to File, which opens the file, evaluates the closure, then closes it again. So this is roughly equivalent to: { File file( "filename" ); // use file } #open:do: could be defined (on class File) like: open: aString do: aBlock |file| file := self open: aString. ^[aBlock value: file] ensure: [file close] where #ensure: is like try/finally in Java. -- Dave Harris, Nottingham, UK [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]