如何找到非可序列化对象的大小? [英] How to find size of Non serializable object?
本文介绍了如何找到非可序列化对象的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到不可序列化对象的大小吗?
请帮忙!!!!
Hi ,
I want to find the size of a non serializable object?
Please help!!!!
推荐答案
我在MSDN上找到了-使用google-免费搜索引擎-每个人都可以使用-在任何地方:
I found this on MSDN - using google - that free search engine - accessible by everyone - everywhere:
public static int GetSizeOfObject(object obj)
{
object Value = null;
int size = 0;
Type type = obj.GetType();
PropertyInfo[] info = type.GetProperties();
foreach(PropertyInfo property in info)
{
Value = property.GetValue(obj,null);
unsafe
{
size += sizeof(Value);
}
}
return size;
}
John Simmons提供的就绪代码是一件好事,您可以在其中添加2/4个字节,以获取对象被引用的次数. (对象引用添加在堆栈中).
问候
鲁西
Ready code provided by John Simmons is good only thing you can add 2/4 bytes in it for how many times your object is getting refer. (Object reference adds in stack).
Regards
Rushi
这篇关于如何找到非可序列化对象的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文