views:

233

answers:

1

When .NET's BinaryFormatter is used to serialize an object graph, is any type of compression applied?

I ask in the context of whether I should worry about the object graph having many repeated strings and integers.

Edit - Hold on, if strings are interned in .NET, there's no need to worry about repeated strings, right?

+7  A: 

No, it doesn't provide any compression but you can compress the output yourself using the GZipStream type.

Edit: Mehrdad has a wonderful example of this technique in his answer to How to compress a .net object instance using gzip.

Edit 2: Strings can be interned but that doesn't mean that every string is interned. I wouldn't make any assumptions on how or why the CLR decides to intern strings as this can change (and has changed) from version to version.

Andrew Hare