[Serialization] How to serialize third party library function
Hello
First all, sorry for my long post, and I hope I will be clear with the
question.
In my project I have a lot of classes, which I plan to serialize with boost
serialization library.
Most of my classes have as members third party library classes. The thing is
that the third party library classes are very complex and I can't serialize
them directly in the standard way i.e I can't say this :
template
I notice that the crash maybe has to do something with that, that my CustomClass implements its own new and delete operators. I know that the default implementation of load_construct data uses operator placement ::new ( global new operator ) to allocate object when loading through pointer, a ** I don't know which version of boost you're using. The most recent version(s) make use of the type trait "has_new_operator" to call a class specific new operator. Without having a specific case to play with I don't know for sure, but it may address you're situation. Robert Ramey
OK, I know installed the latest version of boost, which uses
has_new_operator type trait.
But , know I am getting compiler errors , for this minimal test program :
#include
I notice that the crash maybe has to do something with that, that my CustomClass implements its own new and delete operators.
I know that the default implementation of load_construct data uses operator placement ::new ( global new operator ) to allocate object when loading through pointer, a
** I don't know which version of boost you're using. The most recent version(s) make use of the type trait "has_new_operator" to call a class specific new operator. Without having a specific case to play with I don't know for sure, but it may address you're situation.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG elizabeta petreska wrote:
OK, I know installed the latest version of boost, which uses has_new_operator type trait.
But , know I am getting compiler errors , for this minimal test program :
#include
class A { public: void* operator new(std::size_t); void* operator new[] (size_t); void* operator new(std::size_t, void*); }; int main() { boost::has_new_operator<A>(); }
The compiler errors are :
Error 1: error C2975: 'b1' : invalid template argument for 'boost::type_traits::ice_or', expected compile-time constant expression \libs\boost\inc\boost-1_41\boost\type_traits\has_new_operator.hpp 100
What compile are you using? The code compiles fine for me with Visual C++ 8.0 and 9.0. In Christ, Steven Watanabe
Hello
I am using Visual C++ 8.0 , and can't compile it :(
Can someone else check if the above is compiling with Visual Studio 2005
Thanks
On Mon, Dec 7, 2009 at 10:01 PM, Steven Watanabe
AMDG
elizabeta petreska wrote:
OK, I know installed the latest version of boost, which uses has_new_operator type trait.
But , know I am getting compiler errors , for this minimal test program :
#include
class A { public: void* operator new(std::size_t); void* operator new[] (size_t); void* operator new(std::size_t, void*); }; int main() { boost::has_new_operator<A>(); }
The compiler errors are :
Error 1: error C2975: 'b1' : invalid template argument for 'boost::type_traits::ice_or', expected compile-time constant expression \libs\boost\inc\boost-1_41\boost\type_traits\has_new_operator.hpp 100
What compile are you using? The code compiles fine for me with Visual C++ 8.0 and 9.0.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
----- Original Message ----- From: "elizabeta petreska"
error C2975: 'b1' : invalid template argument for 'boost::type_traits::ice_or', expected compile-time constant expression \libs\boost\inc\boost-1_41\boost\type_traits\has_new_operator.hpp 100
I just tried compiling your code with VS8 (Express Edition) and got the same error. Are you also using Express Edition?
John
Hello
You could also make a template class that handles your serialization of the
third party library classes (you probably want to split save/load). A
wrapper or holder class if you will that should only exist on the stack..
That way you can serialize the classes in any way you want to - while still
getting benifits from the serialization library. The downside is the added
complexity and in my case i had to make sure that pointers are not released
before your done serializing, since the library tracks them (otherwise the
same address could be reused and the serialization library will identify it
as the same object).
Not sure if that is the kind of solution you are looking for though, might
be easier to have the compile error fixed.
Regards
Rune
On Tue, Dec 8, 2009 at 10:12 AM, John Emmas
----- Original Message ----- From: "elizabeta petreska"
error C2975: 'b1' : invalid template argument for 'boost::type_traits::ice_or', expected compile-time constant expression \libs\boost\inc\boost-1_41\boost\type_traits\has_new_operator.hpp 100
I just tried compiling your code with VS8 (Express Edition) and got the same error. Are you also using Express Edition?
John
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You could also make a template class that handles your serialization of
I am using the professional edition of Visual Studio 2005. the third party library classes (you probably want to split save/load). A
wrapper or holder class if you will that should only exist on the stack..
I don't understand you what you mean with this. Sorry , can you explain me a
little ?
Also in this moment I solved the problem with making explicit specialization
for the heap_allocator template , i.e I made the following :
namespace boost
{
namespace archive
{
namespace detail
{
template<>
struct heap_allocator<CustomClass>
{
static CustomClass* invoke()
{
return static_cast
Hello
You could also make a template class that handles your serialization of the third party library classes (you probably want to split save/load). A wrapper or holder class if you will that should only exist on the stack.. That way you can serialize the classes in any way you want to - while still getting benifits from the serialization library. The downside is the added complexity and in my case i had to make sure that pointers are not released before your done serializing, since the library tracks them (otherwise the same address could be reused and the serialization library will identify it as the same object).
Not sure if that is the kind of solution you are looking for though, might be easier to have the compile error fixed.
Regards Rune
On Tue, Dec 8, 2009 at 10:12 AM, John Emmas
wrote: ----- Original Message ----- From: "elizabeta petreska"
error C2975: 'b1' : invalid template argument for 'boost::type_traits::ice_or', expected compile-time constant expression \libs\boost\inc\boost-1_41\boost\type_traits\has_new_operator.hpp 100
I just tried compiling your code with VS8 (Express Edition) and got the same error. Are you also using Express Edition?
John
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
The issue here is the new type_trait and it's usage "has_new_operator". This is a recent addition which likely requires some more fine tuning. There is a track item on this in either the the serialization and/or type_traits libraries. For now this is a pending issue - patches welcome.
Robert Ramey
"elizabeta petreska"
AMDG elizabeta petreska wrote:
Hello I am using Visual C++ 8.0 , and can't compile it :( Can someone else check if the above is compiling with Visual Studio 2008
Apparently the problem has been fixed in the trunk. http://svn.boost.org/trac/boost/changeset/56730 In Christ, Steven Watanabe
Thank you so much. I took the changeset directly from the trunk, and now it
works. I am wondering why this change is not included in the latest version
of boost 1.41.0. The change is made a month earlier , before boost 1.41.0
version is released.
On Tue, Dec 8, 2009 at 5:49 PM, Steven Watanabe
AMDG
elizabeta petreska wrote:
Hello I am using Visual C++ 8.0 , and can't compile it :( Can someone else check if the above is compiling with Visual Studio 2008
Apparently the problem has been fixed in the trunk.
http://svn.boost.org/trac/boost/changeset/56730
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
elizabeta petreska
-
John Emmas
-
Robert Ramey
-
Rune Lund Olesen
-
Steven Watanabe