In the examples in the previous section, the dumping and loading were done using a file stream. However, dumping and loading can also be done on top of streams like ReadWriteStream in memory. Any stream that implements the WriteStream protocol is valid for dumping. The streams can be either on Strings (ReadWriteStream on: String new) or on ByteArrays (ReadWriteStream on: ByteArray new). Since IBM Smalltalk runs on platforms with different character sets (such as ASCII and EBCDIC), it is recommended that streams on ByteArrays be used whenever possible. Any stream that implements the ReadStream protocol is valid for loading.The next example shows how dumping and loading can be done with a ReadWriteStream. ObjectDumper and ObjectLoader use the message isBytes: to ensure that the stream does not use DBStrings (on platforms where this is the default behavior).If repeated dumping is to be done, creating an ObjectDumper and an ObjectLoader that are reused will provide a significant performance improvement over repeatedly creating new instances of these objects because you can avoid the setup cost of creating a dumper and loader.
|