From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32169 invoked by alias); 6 Feb 2011 13:21:24 -0000 Received: (qmail 32155 invoked by uid 22791); 6 Feb 2011 13:21:23 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ka.mail.enyo.de (HELO ka.mail.enyo.de) (87.106.162.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 06 Feb 2011 13:21:18 +0000 Received: from [172.17.135.4] (helo=deneb.enyo.de) by ka.mail.enyo.de with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) id 1Pm4YF-0004nk-NV for gcc-help@gcc.gnu.org; Sun, 06 Feb 2011 14:21:15 +0100 Received: from fw by deneb.enyo.de with local (Exim 4.72) (envelope-from ) id 1Pm4YF-0007mh-GN for gcc-help@gcc.gnu.org; Sun, 06 Feb 2011 14:21:15 +0100 From: Florian Weimer To: gcc-help@gcc.gnu.org Subject: Re: C++ and garbage collection References: <20110204194604.GB12837@nibiru.local> <20110205124139.GB29367@nibiru.local> <20110205144610.GA14734@nibiru.local> Date: Sun, 06 Feb 2011 19:29:00 -0000 In-Reply-To: <20110205144610.GA14734@nibiru.local> (Enrico Weigelt's message of "Sat, 5 Feb 2011 15:46:10 +0100") Message-ID: <87d3n5e1tg.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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/msg00126.txt.bz2 * Enrico Weigelt: >> 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 ? What's the oldest GCC version you're targeting? Modern GCC has std::unique_ptr (zero-overhead pointer wrapper with RAII semantics), std::shared_ptr and std::make_shared (avoiding a separate allocation using operator new). This should work after some adjustments, as long as your data structures are acyclic. You just have to avoid taking short-cuts to optimize things, using references and plain pointers instead of the std:: wrappers. In this regard, Boehm GC is hard to beat.