Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2002-03-23 00:03:44


>
> Umm...pardon my ignorance, but why do you need a
> smart
> pointer to a static object?
>

Please see my other post in this thread.

> Trying to write generic code that works equally well
> with
> static and dynamic pointers is simply not feasible,
> as Peter
> Dimov pointed out.

"not feasible"...hmm...maybe...
Forgive me if I am not too sure in myself :).
However in many cases a brute force
approach might work.
just overload 'delete' and 'new' with something and
make
you own memory heap manager.

void* operator new( ... )
{
   return my_great_heap.allocate(...)
}

void operator delete( void* p )
{
  if( !my_great_heap.is_deletable( p ) ) return;
  my_great_heap.free( p );
}

--- "David B. Held" <dheld_at_[hidden]>
wrote:
> ----- Original Message -----
> From: "E. Gladyshev" <egladysh_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Friday, March 22, 2002 1:10 PM
> Subject: [boost] plain pointers and shared_ptr
>
> > [...]
> > One problem that I'd like to solve is to deal with
> pointers
> > to static objects. I am not sure if there are any
> smart
> > pointer implementations that can reference static
> objects.
> > For example:
> >
> > int g_x;
> > int main()
> > {
> > share_ptr<int> tmp(&g_x)
> > } //CRASH
>
> Umm...pardon my ignorance, but why do you need a
> smart
> pointer to a static object?
>
> Trying to write generic code that works equally well
> with
> static and dynamic pointers is simply not feasible,
> as Peter
> Dimov pointed out. Just as you cannot write generic
> code
> to eliminate the need to use delete [] vs. delete on
> raw
> pointers, you cannot use generic code to properly
> destruct
> or not destruct a raw pointer. There simply isn't
> enough
> information. Instead, you should provide a version
> that
> handles static pointers, and one that accepts smart
> pointers,
> as Peter again pointed out.
>
> Dave
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk