This project is read-only.

is it possible to optimize the serialization of an array of bytes?

Apr 8, 2011 at 2:43 AM

Now this is a very long time!
Not suitable for practical use if the object has a field of type byte array.

Apr 18, 2011 at 9:52 AM

hi, have you solved this problem? if not - do you mean xml or binary serialization? for an xml you could convert your array of bytes to a string property in the form: "v1,v2,v3,..."and serialize this string property. otherwise sharpserializer serializes these bytes as every other array. first it estimates the array type, and then serializes every value.

maybe some performance examples? how long is very long? :-)

sorry for such a late answer, i was not notifed about new discussion thread. bad codeplex... ;-)

Apr 18, 2011 at 4:06 PM

I had no time to experiment.

in the end I took this decision.

Apr 30, 2011 at 5:41 PM

Looking into the sourcecode of version 2.7 there is already an optimisation in the binary formatter of sharpserializer.

namespace Polenter.Serialization.Core.Binary
    public static class BinaryWriterTools
        private static void writeValueCore(object value, BinaryWriter writer)
            if (type == typeof (byte[]))
                writeArrayOfByte((byte[]) value, writer); // write length+rawbites


can you eplain, what is not optimal enough?

Nov 3, 2011 at 2:40 PM

Binary serialization with an array of bytes is overflowing completely. A class with a byte array property with 300k of content gets serialized into a 4M chunk.


Any workaround or fix?


Nov 7, 2011 at 9:03 AM
Edited Nov 7, 2011 at 9:05 AM

it's true, each byte is single serialized. The code from BinaryWriterTools is never reached.

I have created the following work item:

Nov 9, 2011 at 8:04 PM

Since v.2.16 the array of byte is serialized as a simple property. In XML the data is stored as Base64 string. In binary as array length plus array data. It works only for array of byte. Arrays of other primitive types are serialized just like before. Backward compatibility is provided, data serialized with previous versions can be deserialized with SharpSerializer 2.16 and above.

Nov 9, 2011 at 8:07 PM

Great job!