By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Smart pointer solution to this problem?

P: n/a
Hello,

I have a C++ application where I create a message object and pass it along
to different threads for processing.

How can I manage the destruction of this message so that it is automatically
deleted when the last thread or process is done with it?

I suppose the simplest approach might be to clone the object before passing
it along, and make each object that receives this object responsible for its
destruction.

I think a smart pointer might solve this problem, can someone recommend an
implementation?

As you've probably already figured out, I don't know much about smart
pointers ...

-Randy

Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
RJGraham wrote in news:o_********************@giganews.com:
Hello,

I have a C++ application where I create a message object and pass it
along to different threads for processing.

How can I manage the destruction of this message so that it is
automatically deleted when the last thread or process is done with it?

I suppose the simplest approach might be to clone the object before
passing it along, and make each object that receives this object
responsible for its destruction.

I think a smart pointer might solve this problem, can someone
recommend an implementation?
Goto boost http://www.boost.org and get boost::shared_ptr

http://www.boost.org/libs/smart_ptr/shared_ptr.htm

As you've probably already figured out, I don't know much about smart
pointers ...


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

P: n/a
RJGraham wrote:

I suppose the simplest approach might be to clone the object before passing
it along, and make each object that receives this object responsible for its
destruction.
New and delete, in particular, can be expensive operations.
I've encountered one system take 20 minutes to delete a few
10000s pointers as it scurried about trying to coalesce blocks.
I think a smart pointer might solve this problem, can someone recommend an
implementation?


Shared pointers will certainly help as you'll only have one
physical memory allocation Try boost.

Jul 22 '05 #3

P: n/a
> > Hello,

I have a C++ application where I create a message object and pass it
along to different threads for processing.

How can I manage the destruction of this message so that it is
automatically deleted when the last thread or process is done with it?

I suppose the simplest approach might be to clone the object before
passing it along, and make each object that receives this object
responsible for its destruction.

I think a smart pointer might solve this problem, can someone
recommend an implementation?


Goto boost http://www.boost.org and get boost::shared_ptr

http://www.boost.org/libs/smart_ptr/shared_ptr.htm


Thanks Rob !

I'll have a look at the boost library.

-Randy
Jul 22 '05 #4

P: n/a
"lilburne" <li******@godzilla.net> wrote in message
news:bp*************@ID-203936.news.uni-berlin.de...
RJGraham wrote:

I suppose the simplest approach might be to clone the object before passing it along, and make each object that receives this object responsible for its destruction.


New and delete, in particular, can be expensive operations.
I've encountered one system take 20 minutes to delete a few
10000s pointers as it scurried about trying to coalesce blocks.
I think a smart pointer might solve this problem, can someone recommend an implementation?


Shared pointers will certainly help as you'll only have one
physical memory allocation Try boost.


Thanks!

I'll have a look at boost.

-Randy
Jul 22 '05 #5

P: n/a

RJGraham wrote:
[...]
Goto boost http://www.boost.org and get boost::shared_ptr

http://www.boost.org/libs/smart_ptr/shared_ptr.htm
Note that current release versions suck miserably with respect to
threading (stuff is pretty much totally busted on windows, to begin
with).


Thanks Rob !

I'll have a look at the boost library.


Try it with

http://www.pdimov.com/cpp/shared_count_x86_exp2.hpp

and have a look at

http://groups.google.com/groups?selm...95E7D%40web.de
(this one is much better, of course ;-) )

regards,
alexander.

--
http://www.linuxdevices.com/files/mi...posed-rev3.pdf
http://www.opensource.org/licenses/cpl.php
Jul 22 '05 #6

P: n/a
"Alexander Terekhov" <te******@web.de> wrote in message
news:3F***************@web.de...

RJGraham wrote:
[...]
Goto boost http://www.boost.org and get boost::shared_ptr

http://www.boost.org/libs/smart_ptr/shared_ptr.htm
Note that current release versions suck miserably with respect to
threading (stuff is pretty much totally busted on windows, to begin
with).

>


Thanks Rob !

I'll have a look at the boost library.


Try it with

http://www.pdimov.com/cpp/shared_count_x86_exp2.hpp

and have a look at

http://groups.google.com/groups?selm...95E7D%40web.de
(this one is much better, of course ;-) )


I'm a little thick, can you point me to an example using your smart pointer
template?
Also, is it thread safe?

Also, are you suggesting not to use the Boost libraries for a multithreaded
Windows app?
Because that's what I have ;)

How about ZooLib ?

Thanks for your help.

-Randy
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.