sizeof() equivalent for reference types?

前端 未结 6 1316
醉酒成梦
醉酒成梦 2020-11-30 12:20

I\'m looking for a way to get the size of an instance of a reference type. sizeof is only for value types. Is this possible?

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 12:57

    If you can - Serialize it!

    Dim myObjectSize As Long
    
    Dim ms As New IO.MemoryStream
    Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
    bf.Serialize(ms, myObject)
    myObjectSize = ms.Position
    

提交回复
热议问题