If I add the [Serializable]
attribute to a class, does this introduce any overhead? How about if the class is never used in any serialization operations?
views:
84answers:
1
+8
A:
This doesn't add any overhead to the normal runtime use of the object.
Marking a class as Serializable
doesn't even result in a size difference in metadata. It just sets a bit in the typedef flag. (Thanks to thecoop for pointing that out)
JaredPar
2010-09-16 22:12:57
It doesn't actually add overhead; `SerializableAttribute` is a special pseudo-attribute that sets the `Serializable` bit in the `TypeDef` flags. So it doesn't add any metadata overhead.
thecoop
2010-09-16 22:16:07
@thecoop, interesting had no idea abouth that. Updated my answer.
JaredPar
2010-09-16 22:20:08
@JaredPar: Out of curiosity, what part of .NET are you working on? Just wondering.
Joan Venge
2010-09-16 23:42:23
@Joan, I used to work on the C# and Vb.net languages team but now work on a language and operating system incubation project.
JaredPar
2010-09-17 03:51:17
@JaredPar: Thanks Jared. Thought you had something to do with C# .NET so wanted to make sure if I remember it correctly. Cheers.
Joan Venge
2010-09-17 16:32:58