Boost logo

Boost :

From: Brian Hawkins (bmhmaillist_at_[hidden])
Date: 2002-04-19 00:39:38


Hi all,

I also would like to see a smart pointer that uses an object ID (or handle)
as a method of reference. I have written and used one for a slightly
different reason, checking to see if the pointer still points to a valid
object. Unfortunately the class still has a long way to go before it can be
general.

The main reason I use this type of class is for game development, there are
a large number of places objects may be reference but game objects can die
at any moment. I don't want to store a list of pointers to update, so the
pointers store a handle so they can validate themselves. I use a simple
handle technique that uses an array index mixed with a unique ID for false
lookup and validation.

Anyhow, I would like to see a pointer with these properties (or policies for
a policy based smart pointer) and would be happy to contribute my
experiences.

Thanks,
Brian Hawkins

-----Original Message-----
From: boost-admin_at_[hidden] [mailto:boost-admin_at_[hidden]]On
Behalf Of David B. Held
Sent: Thursday, April 18, 2002 10:58 AM
To: boost_at_[hidden]
Subject: [boost] Re:Serializable smart pointer

Another thing I'd like to see is what I call a serializable smart pointer.
This is just a smart pointer that stores either a pointer or an int, so it's
like a variant. I store object IDs, which is what I would load into the
pointer on initialization, and then do a fixup after all relevant objects
are loaded. Right now, I do this in a wrapper I wrote, which may
be the preferred way to do it. But it seems to me a bit more elegant
to do it in the smart pointer itself.

I used boost::shared_ptr as the smart pointer type in my wrapper.
Since it has a c'tor, d'tor, etc., I couldn't put it in a union with an
int. So I borrowed ideas from Andrei's value-based variant type,
and created my own variant<int, shared_ptr> that forwards some
of shared_ptr's interface, but allows me to store an int as well. If
the smart pointer itself implemented the two types, it *could* store
the int (or long) in a union with the raw pointer. This would avoid
a lot of messiness in dealing with a value-based discriminated union.

If there is a better way to save and load pointers, I'd be glad to
hear it. If this kind of feature just doesn't belong in a smart pointer,
I'd like to know why (I'm easy to convince, I just need to see a
good explanation). If this is possible to implement as a policy with
Loki::SmartPtr, I'd like to see a basic sketch. From what I can tell,
it isn't, since it would require a bit more interface than SmartPtr has
(one would need a way to store and fetch two different types). I
know Jens Maurer has written a persistence library, but it doesn't
seem to address pointer persistence directly (it looks like it assumes
that the user will deal with pointers herself).

I also know there has been a lot of discussion on persistence and
serialization; but again, they seem to be discussions that get stalled,
with no concrete results that I can use now. Without tackling
generalized persistence (which I can deal with myself right now),
is it possible to at least get a serializable pointer down?

Dave

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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