From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21101 invoked by alias); 6 Feb 2011 19:29:51 -0000 Received: (qmail 21093 invoked by uid 22791); 6 Feb 2011 19:29:51 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 06 Feb 2011 19:29:44 +0000 Received: by iyj8 with SMTP id 8so1589361iyj.20 for ; Sun, 06 Feb 2011 11:29:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.225.133 with SMTP id is5mr11265182icb.325.1297020582831; Sun, 06 Feb 2011 11:29:42 -0800 (PST) Received: by 10.42.230.68 with HTTP; Sun, 6 Feb 2011 11:29:42 -0800 (PST) In-Reply-To: <20110205144610.GA14734@nibiru.local> References: <20110204194604.GB12837@nibiru.local> <20110205124139.GB29367@nibiru.local> <20110205144610.GA14734@nibiru.local> Date: Sun, 06 Feb 2011 23:01:00 -0000 Message-ID: Subject: Re: C++ and garbage collection From: Jonathan Wakely To: weigelt@metux.de, gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00127.txt.bz2 On 5 February 2011 14:46, Enrico Weigelt wrote: >> > >> >> One viable approach is to modify the uses of pointers into shared_ptr >> >> (from TR1 or boost) and then add the Boehm collector. =A0This process >> >> takes work, because changing all pointers won't work and changing >> >> none won't buy you anything. >> > >> > Guess this would take a lot of work and add more dependencies >> > (than just the relatively small boehm-gc lib) ... >> >> GCC includes a tr1::shared_ptr so there's no extra dependency if you >> are only planning to use g++, and std::shared_ptr is part of C++0x. > > How does that one actually work and what do I have to do to use it ? #include int main() { using std::tr1::shared_ptr; shared_ptr p(new int); *p =3D 5; assert( *p =3D=3D 5 ); shared_ptr p2(p); assert( p =3D=3D p2 ); assert( p.use_count() =3D=3D 2 ); p.reset(); assert( p.use_count() =3D=3D 0 ); assert( p2.use_count() =3D=3D 1 ); } // int deleted here for more info read the docs for boost::shared_ptr (where the class originated) or search the web, there is plenty of info on shared_ptr.