| View previous topic :: View next topic |
| Author |
Message |
daaa57150
Joined: 17 Nov 2006 Posts: 28
|
Posted: Wed Apr 09, 2008 5:47 pm Post subject: serialization |
|
|
Hi,
is there a library somewhere I can use for serializing my objects?
I found that but it's not usable on cygwin.
did someone already do serialization on his own?
I need it for saving profiles (scores etc) into binary files for a beginning but I think I'll need it if I implement multiplayer one day.. |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Wed Apr 09, 2008 6:05 pm Post subject: |
|
|
| As long as C++ does support polymorphism, inheritance and the other nice things we are used to, generic serialization through so called "reflection" is something commonly done only by managed code (java,.net,mono). With this i'm not teling this cannot be done (if code has to be polymorphic, all naming data and method signatures are to be stored) but i'm telling that even use this (if you have not to implement yourself) would be a pain in the a**. Don't know of any specific library, but a quick search on google will show many. However, my suggestion remains: "implement specific serializeMe() and deSerializeMe() methods in your class"... |
|
| Back to top |
|
 |
daaa57150
Joined: 17 Nov 2006 Posts: 28
|
Posted: Wed Apr 09, 2008 6:08 pm Post subject: |
|
|
| jean wrote: | | As long as C++ does support polymorphism, inheritance and the other nice things we are used to, generic serialization through so called "reflection" is something commonly done only by managed code (java,.net,mono). With this i'm not teling this cannot be done (if code has to be polymorphic, all naming data and method signatures are to be stored) but i'm telling that even use this (if you have not to implement yourself) would be a pain in the a**. Don't know of any specific library, but a quick search on google will show many. However, my suggestion remains: "implement specific serializeMe() and deSerializeMe() methods in your class"... |
I'm thinking the same thing: much easier to implement serialization/deserialization functions myself :( |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Apr 09, 2008 9:34 pm Post subject: |
|
|
Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
daaa57150
Joined: 17 Nov 2006 Posts: 28
|
Posted: Wed Apr 09, 2008 9:38 pm Post subject: |
|
|
| Jim wrote: | Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.
Jim |
this may work with simple structures, but with pointers or members containing pointers (std containers for example) only the memory address will be written and not the data pointed. |
|
| Back to top |
|
 |
gauri
Joined: 20 Jan 2008 Posts: 35 Location: Belarus
|
Posted: Thu Apr 10, 2008 3:37 pm Post subject: |
|
|
| Jim wrote: | | Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand. |
You will fail epically if your classes have virtual functions (and hence a pointer to vtbl) or you keep pointers to some other stuff.
One way to fix vtable issue is to really write the whole object at a time and then when reading it back call placement new on it, which will restore vtable ptrs. _________________ Freelance game industry veteran. 8] |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Thu Apr 10, 2008 9:55 pm Post subject: |
|
|
| No need to end up to complex things. Just derive all serialilzable classes from an ancestor IMySerializable that exports virtual doSerializeTo(stream) and unSerializeFrom(stream) methods. Then, in your method implementations (un)serialize all primitive types as you wish, and then recurr calling serialization methods on class fields. This is just how java implements this :) |
|
| Back to top |
|
 |
pspZorba
Joined: 22 Sep 2007 Posts: 156 Location: NY
|
Posted: Thu Apr 10, 2008 10:21 pm Post subject: |
|
|
You will need to save the object type too, in order to be able to re-instranciate it when you re-read it (use a Param factory for the instanciation). _________________ --pspZorba--
NO to K1.5 ! |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Apr 10, 2008 11:16 pm Post subject: |
|
|
Your high score tables have pointers in to other data structures?!
Come on, .net style serialization isn't necessary here.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
daaa57150
Joined: 17 Nov 2006 Posts: 28
|
Posted: Fri Apr 11, 2008 4:57 pm Post subject: |
|
|
| Jim wrote: | Your high score tables have pointers in to other data structures?!
Come on, .net style serialization isn't necessary here. |
True, score tables can be done like you said, it's just that I want to do things properly if I can, and serialization can be useful for other things like data transfer between 2 PSPs for multiplayer and whatnot. And by the way, it's in fact "profiles" that I want to save, which have pointers to score tables for each levels alongside primitive types.
| jean wrote: | | No need to end up to complex things. Just derive all serialilzable classes from an ancestor IMySerializable that exports virtual doSerializeTo(stream) and unSerializeFrom(stream) methods. Then, in your method implementations (un)serialize all primitive types as you wish, and then recurr calling serialization methods on class fields. This is just how java implements this :) |
| pspZorba wrote: | | You will need to save the object type too, in order to be able to re-instranciate it when you re-read it (use a Param factory for the instanciation). |
Thanks guys, that will be helpful. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Fri Apr 11, 2008 11:14 pm Post subject: |
|
|
| Quote: | | serialization can be useful for other things like data transfer between 2 PSPs for multiplayer and whatnot |
I don't grok this either. Are you expecting the PSP on the other end of the connection to be running different-endian, different-ieee754, different CPU, different OS, different vendor, different anything?
I suspect not. This is embedded programming you're doing here, not business.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
miniJB
Joined: 06 Apr 2008 Posts: 5
|
Posted: Fri Apr 11, 2008 11:42 pm Post subject: |
|
|
Boost.Serialization could be an option (using the boost4psp jamfiles to build it)...
Boost.Build doesnt detect the pspsdk cygwin environment as supporting wide chars (it IS missing a few functions...) but the non-wide serialisation part of the library compiles fine.
I havent tested it yet though, so if it works let me know ;) |
|
| Back to top |
|
 |
|