Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization calling a customserialize method
From: pooyan_at_[hidden]
Date: 2010-08-20 04:40:16


On Wed, 18 Aug 2010 10:37:14 -0800, "Robert Ramey" <ramey_at_[hidden]> wrote:
> 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);
> }
>
> with
>
> template<class TArchiveType>
> Variable::serialize(TArchiveType &rArchive, const unsigned int Version,
> void* pValue)
> {
> rArchive & static_cast<TDataType * >(pVAlue);
> }
>

Sorry, The missing * was a typo error. Casting to a pointer was what I
mean.

But still I have the problem of how call this method in my container:

typedef std::pair<const VariableData*, void*> my_data_type;

template<class Archive>
void serialize(Archive & ar, my_data_type & data, const unsigned int
version)
{
    data.first->Serialize(ar, version, data.second); // Note that the
first is a pointer to the base class and I want to call the
                                                     // serialize of the
derived class which is not virtual
}

Consider that the data.first is a pointer to the base class and I want to
call the serialize of the derived class which is not virtual

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

Really I'm not aware of a storage mechanism for a heterogeneous container
without using virtual functions in time of accessing data which means less
performace for us. In this sudo code the accessing mechanism is not
menssioned but it is fast and typesafe (it can be seen here
http://kratos.cimne.upc.es/trac/browser/kratos/kratos/containers/data_value_container.h)

Of course any suggestion will be very welcome!!

Thanks,

Pooyan.

> Robert Ramey
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net