Author |
Message |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Fri Nov 24, 2006 3:34 pm Post subject: object serialization |
|
|
i am having trouble understanding the concept of object serialization. When would i need or benefit from using object serialization over another way of reading/writing files? what is the difference between making a random access file (using records) and object serialization?
Thank you |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Nov 24, 2006 4:10 pm Post subject: (No subject) |
|
|
Well, if you simply write out the representation of an object in memory to a file, then you're a slave to that particular representation.
If you use some independent serialization format, then you can take an object, serialize it, and then load it in a program written in an entirely different language, or an implementation of the same language with a different way of representing that object in memory. |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Fri Nov 24, 2006 4:14 pm Post subject: (No subject) |
|
|
wtd wrote: Well, if you simply write out the representation of an object in memory to a file, then you're a slave to that particular representation.
If you use some independent serialization format, then you can take an object, serialize it, and then load it in a program written in an entirely different language, or an implementation of the same language with a different way of representing that object in memory.
when you say slave can you be a little more specific by what you mean. Also if i did not need to make another program and get the object information and i was just making a simple program writing/reading to a file what would be the advantage to using serialization? |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Nov 24, 2006 4:24 pm Post subject: (No subject) |
|
|
Well, if you write out the exact in-memory representation of a data structure, and then some time later an update to the environment changes how that data structure is represented...
what happens? |
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Fri Nov 24, 2006 5:03 pm Post subject: (No subject) |
|
|
wtd wrote: Well, if you write out the exact in-memory representation of a data structure, and then some time later an update to the environment changes how that data structure is represented...
what happens?
i'm assuming it will no longer work. And i am assuming if i used object serialization it will work. however, lets say i was making some inventory program for a store where the program they are using will not change. yes i know stores do update their programs but lets say it will not change. What would be my advantage in using object serialization then?
From what i can see the only advantage to object serialization is that it can work on multi platforms (different programming languages) and if something changes with the platform it will still work. But lets say i had to do a homework assignment which gave me the choice to use any type of method to read and write files what will be my advantage to use object serialization or in what specific case would i use it. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
cool dude
![](http://www.taylorstrategicmarketing.com/images/king.jpg)
|
Posted: Fri Nov 24, 2006 5:19 pm Post subject: (No subject) |
|
|
Tony wrote: the benifit of enforcing good practice ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif)
good practice for what tony? if there is no advantage to it accept for the one that wtd mentioned then i would rather practice making random access files. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Fri Nov 24, 2006 5:46 pm Post subject: (No subject) |
|
|
If you're creating a program to manage a store's inventory, then your model should be a database. This handily solves your serialization concerns.
For lightweight databases I would suggest something like SQLite. No database server is involved. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
md
![](http://compsci.ca/v3/uploads/user_avatars/1849317514ed6c4399768d.png)
|
Posted: Fri Nov 24, 2006 10:34 pm Post subject: (No subject) |
|
|
Serialization is required for any kind of serious network code. Sending things over a network as an in-memory representation completely breaks portability. Even the same source compiled with different compilers may have different in-memory representations.
Even when you are just using files serialization is a very good idea for the same reasons. Data files need to be portable, otherwise a minor change in the compiler (even just different compile options) can break your program in bizarre and very hard to trace ways.
Incidentally object serialization in Java is an oft studied problem which has many many good (ans usually quite simple) solutions. |
|
|
|
|
![](images/spacer.gif) |
|