开发者

Does a variable in occupy the same space in memory as when serialized?

if the class was had a SerializableAttribute and its object was serialized with BinaryFormatter, the serialized size is equal to the size it occupied in memory?

Edit: Additional question: is there a better way to find how much space an object oc开发者_运维知识库cupies in the memory? is this method approximate enough?


No. The members of a class/structure is stored in memory with padding to align them on an even word boundary when needed (according to respective data type). The serialised data has no such padding.


Typically, serialized objects occupy more space, because explicit metadata has to be stored as well. However, in the memory space of the running process there is metadata also, so how do you account for the metadata part to make a correct comparison?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜