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 6 1955
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/
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.
> > 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
"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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shankar |
last post by:
Hello,
We have a smart pointer class which provides the dereference
operator -> to access the underlying object pointer. Now, we have a new
requirement where a different type of object (e.g from...
|
by: Matthias Kaeppler |
last post by:
Hi,
I'm having a hard time figuring out how I can initialize a smart pointer
based on a certain condition:
if something then
ptr = 0; // init with NULL
else
ptr = new XYZ; // init with a...
|
by: zl2k |
last post by:
hi,
When I considered about preventing memory leaking, the method came up
to my mind is using boost smart pointer if possible (use stl::vector
instead of type, use smart pointer whenever declare...
|
by: Boris |
last post by:
I've a class C with a smart pointer (I use boost::shared_ptr) which is
initialized in the constructor:
class C {
boost::shared_ptr<D> d;
public:
C() : d(new d()) { }
};
When the program...
|
by: Jim Langston |
last post by:
Someone made the statement in a newsgroup that most C++ programmers use
smart pointers. His actual phrase was "most of us" but I really don't think
that most C++ programmers use smart pointers,...
|
by: Ney André de Mello Zunino |
last post by:
Hello.
I have written a simple reference-counting smart pointer class template
called RefCountPtr<T>. It works in conjunction with another class,
ReferenceCountable, which is responsible for the...
|
by: Boris |
last post by:
I had a 3 hours meeting today with some fellow programmers that are partly
not convinced about using smart pointers in C++. Their main concern is a
possible performance impact. I've been explaining...
|
by: sip.address |
last post by:
I'm using reference counted smart pointers in a small project and it's
a breeze, but I'm running into a problem which I don't know how to
approach.
Consider something like this:
class A {...
|
by: Soumen |
last post by:
Hi,
I've requirement to observe a raw pointer (i.e. I should be able to
query if the pointer I'm using is still valid or not but when the
observer goes out of scope, the resource -- memory --...
|
by: Juha Nieminen |
last post by:
I asked a long time ago in this group how to make a smart pointer
which works with incomplete types. I got this answer (only relevant
parts included):
...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |