Boost logo

Boost Users :

Subject: Re: [Boost-users] Clarification on Array, UNION serialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-02-18 02:04:47


  "niranjan bangera" <niranjannina_at_[hidden]> wrote in message news:50a2f6f20902172223s69f3d39ft2b337c0c3ec6dbbc_at_mail.gmail.com...
  Hi all,
             I want to clarify myself in serialization of union and array, Please clarify my doubts.
             
  Boost Version:1.36.0
  Compiler :/_TOOLS_/dist/gnu-gcc-/4.1.1-binutils-2.16.1/x86_64-pc-linux2.4/bin/gcc

  class A {
  union my_union {
    
           uint64_t array1[ 4];
           int64_t array2[4];
           double dbl [4];
           uint32_t array3 [ 8 ];
           int32_t array4 [ 8 ];
           float flt [ 8];
           uint16_t array5[ 16 ];
           int16_t array6[ 16 ];
           uint8_t array7 [ 32 ];
           int8_t arrray8[ 32 ];
  }
                my_union my_obj;
                friend class boost::serialization::access;
                template<class Archive>
                void serialize(Archive & ar, const unsigned int file_version)
                {
                     ar & my_obj.array1;
                 }
  };
  Is it safe to do it, or any othe optimised method is there to do it?

  This should work if my_union in fact contains array1[4]. But what happens if it contains something else.
  Look into variant which is typesafe AND already serializable.
                
  how to serialize a dynamicaly allocated array

  struc my_struct{
                                 int x;
  }

  struct new_struct {
  {

  my_struct **my_var; ///my_struct is a structure defined before this structure.

  }
   
  Currently, pointers to pointers cannot be serialized. This is the subject of a TRAK item.

  In this case do i need to serialize each element int the array manually, Pointed By my_var

  Consider using a pointer to an std::vector. Serialization is free for this case.

  Is there other some other way to do it...

  Thanks,
  Niranjan

  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