Slowness in Serialize

  • Thread starter Thread starter _BNC
  • Start date Start date
B

_BNC

I've got an ArrayList of objects that I'd like to save/retrieve as quickly
as possible. Each item in the arraylist is an object with about 50
variable-length strings; many zero-length, some about 80 chars or so,
if that matters.

I figured I'd set the [Serializable] attribute on the object and on the
ArrayList and use standard Serialize() functions. This is just incredibly
slow. Is that normal? Any other recommended approach?

The function itself is listed below, but I think it's boilerplate:

private bool Serialize(string Filename) {
FileStream binfs;
IFormatter ifmtr = new BinaryFormatter();
bool retval = true;
binfs = new FileStream(
Filename, // expect full path and file name
FileMode.Create,
FileAccess.Write,
FileShare.None);
try {
ifmtr.Serialize(binfs, this);
binfs.Close();
} catch (SerializationException ex) {
// MessageBox.Show(ex.ToString());
retval = false;
}
return retval;
}
 
Usually the *first time is really slow cause the assembly is loaded. The
next times should be faster. Serialization is still going to be a bit slow.
I think they made some improvements in Whidbey.
 
Usually the *first time is really slow cause the assembly is loaded. The
next times should be faster. Serialization is still going to be a bit slow.
I think they made some improvements in Whidbey.

I hope so. I was trying to replace a somewhat slow XML parser (the
original file was a proprietary XML format). I was shocked to find out
that the binary serialize was several times slower at storing the info
than the XML parser. That doesn't make much sense.
 
Back
Top