From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: weigelt@metux.de, gcc-help@gcc.gnu.org
Subject: Re: C++ and garbage collection
Date: Sun, 06 Feb 2011 23:01:00 -0000 [thread overview]
Message-ID: <AANLkTi=geKqxML4bOgErAauweMXJSuXDJnPgerZStoc2@mail.gmail.com> (raw)
In-Reply-To: <20110205144610.GA14734@nibiru.local>
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. This 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 <tr1/memory>
int main()
{
using std::tr1::shared_ptr;
shared_ptr<int> p(new int);
*p = 5;
assert( *p == 5 );
shared_ptr<int> p2(p);
assert( p == p2 );
assert( p.use_count() == 2 );
p.reset();
assert( p.use_count() == 0 );
assert( p2.use_count() == 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.
prev parent reply other threads:[~2011-02-06 19:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-04 20:25 Enrico Weigelt
2011-02-04 22:13 ` Florian Weimer
2011-02-05 12:51 ` Enrico Weigelt
2011-02-05 0:03 ` Jonathan Wakely
2011-02-05 4:25 ` Lawrence Crowl
2011-02-05 14:37 ` Enrico Weigelt
2011-02-05 14:43 ` Jonathan Wakely
2011-02-05 14:56 ` Enrico Weigelt
2011-02-06 19:29 ` Florian Weimer
2011-02-07 6:41 ` Enrico Weigelt
2011-02-07 18:50 ` Florian Weimer
2011-02-12 20:55 ` Enrico Weigelt
2011-02-06 23:01 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTi=geKqxML4bOgErAauweMXJSuXDJnPgerZStoc2@mail.gmail.com' \
--to=jwakely.gcc@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=weigelt@metux.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).