Re: non destructable pointer
In article <4hnhfnFebg4U1@individual.net>, Pavel Vozenilek
<pavel_vozenilek@yahoo.co.uk> wrote:
"Pete Becker" wrote:
TR1's shared_ptr (as well as Boost's, on which it was based) can be
used. All you need to do is provide a deleter object that doesn't do
anything.
struct MyTy
{
// whatever
};
struct null_deleter
{
void operator()(MyTy*) {}
};
int main()
{
MyTy obj;
shared_ptr<MyTy> ptr(&obj, null_deleter());
return 0;
}
This solution has overhead of locking
the shared_ptr every time when it is copied.
Passing shared_ptr by value is quite expensive
(not just a value in register).
A simple "dumb_ptr", without any overhead
at all may be useful.
Locking is an implementation detail of boost's version. Tr1's version
makes no reference to threads or locks. Surely you can disable thread
safety in the boost version, but I leave the expert/author determine if
this possible. Seems like thread safety is more important than speed.
and if it is not and you work for me, your fired.:)
now if copying a shared_ptr is a problem don't pass it by reference....
Boost's intrusive_ptr can also be used for the OP's problem if the
class can be modified. needs a long, a bool a couple of friend
functions and modifying the ctors to properly initialise the added
members. call the ctor with different args for new'ed data and static
data. done.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]