Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization calling a customserialize method
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-08-18 14:37:14

Pooyan Dadvand wrote:
> Hi again,
> In this project the variable is in charge of storing all information
> about any data (like DISPLACEMENT) which is its name, default value,
> unique key, etc, and perform all necessary operations with its type
> of data. In serializing std::pair<const VariableData*, void*> who
> knows the type of the value pointed by the void* is the Variable
> pointed by a base class pointer. So for serializing I need to call a
> method of Variable (which has the type information) and pass the
> void* which is the value to be store. This value can be a simple
> double, ublas matrix or even more complex classes. I know that this
> looks strange from OO point of view but the variable itself don't
> have any pointer to its value because there are few hundred variables
> in Kratos and in a normal analysis we have to store millions of
> values in the data structure. So using the variable as handler of its
> value will cause a very big overhead of memory which is not
> acceptable.
> Thanks,
> Pooyan.
> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
> Sent: 18 August 2010 18:18
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Boost Serialization calling a custom
> serialize method
> Pooyan Dadvand wrote:
>> Hi,
>> I'm trying to use the boost serialization in our project "Kratos" (a
>> Multi-physics finite element code) in which I found the following
>> problem, I have a class Variable which is derived from VariableData
>> as follow:
>> Class VariableData
>> {
>> std::size_t mKey;
>> public:
>> .....
>> };
>> template<class TDataType>
>> class Variable : public VariableData
>> {
>> ....
>> }
> Seems to me that what would work is:
> Class VariableData{
> std::size_t m_Key;
> public:
> virtual ~VariableData() = 0;
> };
> template<class TDataType>
> class Veriable : public VariableData {
> ...
> }
> This would work with the library in a normal way.
>> Now I have a container which holds a pairs, consist of VariableData
>> pointer to the Variable and a void* pointer to its value:
>> std::vector<std::pair<const VariableData*, void*> >
> I can't understand what the "void *" could possibly be useful for
> here. Nor can I understand why you would use it. The whole idea
> of trying to serialize a "void *" seems totally non-sensical to me. I
> have no idea how or way one would want to do this.
> Robert Ramey

maybe what you want is to replace:

template<class TArchiveType>
Variable::serialize(TArchiveType &rArchive, const unsigned int Version,
void* pValue)
                rArchive & static_cast<TDataType>(pVAlue);


template<class TArchiveType>
Variable::serialize(TArchiveType &rArchive, const unsigned int Version,
void* pValue)
                rArchive & static_cast<TDataType * >(pVAlue);

which still looks like a bad idea to me. But it might be what you want.

Robert Ramey

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at