[serialization][1.49]How to serialize shared_ptr<void>?
Hi,:) I'm doing saving the shared_ptr<void>,but it can't as "boost::serialization::tracking_level< T >::value != boost::serialization::track_never". And I know if it's shared_ptr<int>,I can use strong_typedef.But for the void,the strong_typedef cannot work. So can you give me some hint? Thanks, Harry -- View this message in context: http://boost.2283326.n4.nabble.com/serialization-1-49-How-to-serialize-share... Sent from the Boost - Users mailing list archive at Nabble.com.
harr999y wrote:
Hi,:) I'm doing saving the shared_ptr<void>,but it can't as "boost::serialization::tracking_level< T >::value != boost::serialization::track_never". And I know if it's shared_ptr<int>,I can use strong_typedef.But for the void,the strong_typedef cannot work. So can you give me some hint?
hmmm - shared_ptr<T> is basically a wrapper around T *. Given X x; X * xptr = & x; shared_ptr<X> sx(x); ar << sx Is more or less equivalent to: serialize x serialize xptr; serialize sx So if X is void the whole thing makes no sense and can't work. You really need to think about what void * means in your program. Usually it's just a place holder for any kind of pointer. Maybe you want to consider using boost::any instead of void *, (I don't know if serialization has been implemented for boost::any) or perhaps boost::variant which DOES have serialization implemented. Robert Ramey
Thanks,
Harry
Thanks the reply,Robert Ramey.And thanks for your great lib. I use void * to specify a sequence raw data.And why I need to use void is that I have many types to store,but I just want one kind type to handle it,convert when use. As you said,I considered about the boost::any,but donnot find the implementation. And it's a good hint for the boost::variant you pointed.I'll go to try it. Thanks again.:) Harry -- View this message in context: http://boost.2283326.n4.nabble.com/serialization-1-49-How-to-serialize-share... Sent from the Boost - Users mailing list archive at Nabble.com.
Robert Ramey wrote
You really need to think about what void * means in your program. Usually it's just a place holder for any kind of pointer. Maybe you want to consider using boost::any instead of void *, (I don't know if serialization has been implemented for boost::any) or perhaps boost::variant which DOES have serialization implemented.
Robert Ramey _______________________________________________ Boost-users mailing list Boost-users@.boost http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi,Robert Ramey.I come back,when I discover about the boost::variant,I find
it cannot satisfy my request.
And finally I use vector to solve it,with the thinking that vector can store
memory.Cheers!
That's what I want to share,and maybe it's helpful to someone who want to
store a sequence raw data with serialization.
I create a vector like:
Engine::Uint8Vector dataVec((sizeof(type) /
sizeof(Engine::Uint8Vector::value_type)) * indexCount);
and then when I need the data to read or modify,just :
type * data = reinterpret_cast
participants (2)
-
harr999y
-
Robert Ramey