
Date: Sun, 15 May 2005 12:00:55 +0100 From: Jean-Fran?ois Brouillet <verec@mac.com> Subject: [Boost-users] Re: shared_ptr, intrusive_ptr ... To: boost-users@lists.boost.org Message-ID: <A42134A2-8F76-4A80-956A-D0070056100F@mac.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
On 2005-05-15 00:49:54 +0100, "Peter Dimov" <pdimov@mmltd.net> said:
Anyway, here's my revised snippet that satisfies all my criteria: -- JFB
#include <iostream>
#include <boost/intrusive_ptr.hpp>
struct ObjectStruct { int refCount ;
ObjectStruct() : refCount(0) { std::cout << std::hex << (int) this << " - I'm born" << std::endl ; }
void refer() { ++refCount ; } void unrefer() { if (--refCount == 0) delete this ; }
virtual ~ObjectStruct() { std::cout << std::hex << (int) this << " - I'm gone" << std::endl ; } } ;
void intrusive_ptr_add_ref(ObjectStruct * p) { p->refer() ; } void intrusive_ptr_release(ObjectStruct * p) { p->unrefer() ; }
Are you going to make it thread-safe (or is that something you just left out of the example?)?