Smart pointer solution to this problem?

R

RJGraham

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
 
R

Rob Williscroft

RJGraham wrote in
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.
 
L

lilburne

RJGraham said:
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.
 
R

RJGraham

lilburne said:
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.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,382
Latest member
MichaleStr

Latest Threads

Top