Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Class testTemplate

    Public tid As Long
    Public emp01(400) As Byte
    Public emp02(400) As Byte

End Class


now i declare a object of the testTemplate class

VB
Dim t As New testTemplate


now i just want to know how can i calculate the memory used or object size in vb.net
using vb.net function.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Sep-13 14:49pm    
My question would be: why? This question is not as trivial as it may seem.
—SA

1 solution

Basically you can't, without some fairly advanced use of Reflection to recursively parse your type and get the sizes of each of it's constituent parts - which may well have their own contained classes, which may... you get the idea.

And it'll be sloooow.

There is apparently another way. Have a look at this: http://blog.softwx.net/2013/01/benchmarking-c-struct-and-object-sizes.html[^] it's C#, not VB, but it does do the job - apparently, I haven't tried it. I have serious doubts about it's accuracy, given that the code tries up to twelve times to get a consistent result on the same object...if the GC won't tell you the same thing twice in a row, what hope have you got?

Part of the idea of .NET is that for most applications, you aren't supposed to think about the size of your objects - just get on an use them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900