[serialization] dynamic arrays of chars
I have a parser and there is one big object that holds the whole file being parsed as a dynamic array class File { public char * ptr; }; File file; file.ptr = new char[very_big_number_like_100000]; The parser creates a lot of objects that keep pointers into this dynamic array. class A { char* internalPtr1; }; class B { char* internalPtr2; }; class C { char* internalPtr3; }; A a; B b; C c; a.internalPtr1 = file.ptr + 234; b.internalPtr2 = file.ptr + 10673; c.internalPtr3 = file.ptr + 9583; How could I serialize the file object and these numerous small objects? I could write separate save/load for each of these A, B, C and so on but I'll need access to File::ptr inside the save/load funcs and this would be an ugly solution. Any ideas?
You could do the following: a) serialize your gigantic character array. b) For each pointer you want to serialize serialize the displacement from the front of your array save( ?; // save to huge array using binary object unsigned int disp; disp = A - file.ptr; ar << disp; disp = B - file.ptr; ... } load( ?; // load huge array using binary object unsigned integer disp; ar >> disp a = file.ptr + disp; ar >> disp a = file.ptr + disp; ... } Good Luck Robert Ramey
I am trying to automate object serialization to the extent that C++ programmers would put a macro into each class they want to serialize and not do anything else. Much the same way as with the [serializable] attribute in C# or Serializable interface in Java. I have a preprocessor that generates template <class Archive> void serialize(Archive &s ... ) function for each class the programmer wants to serialize and I require the programmer to link against boost::serialization. Now with this char* I need a solution that would not require the objects A, B, C and so on to know about the file.ptr. In other words the generated serialize funcs for A, B, C ... should not include code that uses file.ptr This is actually why I need access to the internal IDs of objects that I was asking about in the other post with a subject: [serialization] how for a particular object to get ID that is assigned by the lib Ivan Robert Ramey wrote:
You could do the following:
a) serialize your gigantic character array. b) For each pointer you want to serialize serialize the displacement from the front of your array
save( ?; // save to huge array using binary object unsigned int disp; disp = A - file.ptr; ar << disp; disp = B - file.ptr; ... }
load( ?; // load huge array using binary object unsigned integer disp; ar >> disp a = file.ptr + disp; ar >> disp a = file.ptr + disp; ... }
Good Luck
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Ivan
-
Robert Ramey