SizeOf operator

  • Thread starter Thread starter Christopher Pragash
  • Start date Start date
C

Christopher Pragash

Hello All,

Is there an equivalent of SizeOf operator in VB.NET? What I'm trying to
achieve is to determine at runtime what the size of hashtable is in terms of
the memory it occupies.

Thanks in advance,
chris
 
Christopher Pragash said:
Hello All,

Is there an equivalent of SizeOf operator in VB.NET? What I'm trying to
achieve is to determine at runtime what the size of hashtable is in terms of
the memory it occupies.

Have you tried SizeOf( ) ?

=)

System.Runtime.InteropServices.Marshal.SizeOf( [Type | Object] )

HTH,
Jeremy
 
Try Reflection.Marshal.SizeOf, but I fear this may only return the size of
the class, not the contents in memory, I'm not sure though. Give it a try.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"


: Hello All,
:
: Is there an equivalent of SizeOf operator in VB.NET? What I'm trying to
: achieve is to determine at runtime what the size of hashtable is in terms
of
: the memory it occupies.
:
: Thanks in advance,
: chris
:
:
 
Christopher,
Unfortunately due to the way objects & memory is laid out there is no SizeOf
operator in .NET per se.

There is System.Runtime.InteropServices.Marshal.Sizeof which returns the
unmanaged size of an object in bytes. Useful only for P/Invoke calls to
unmanaged code. It is not the size of the managed object itself!

It will not give a meaningful number for HashTables as a HashTable is an
object that references other objects, which reference still other objects.

Hope this helps
Jay
 
Jay,

Thanks for the Response. I did try the Marshal.SizeOf, but as you mentioned
it does not work for Hashtable. Is there any other way that this could be
achieved?

Thanks again,
Chris
 
Hello Tom,

Thanks for the response. You are right, the Marshal.SizeOf does not work. Is
there another mechanism you could think of?

Thanks,
Chris
 
Hello,

Christopher Pragash said:
Is there an equivalent of SizeOf operator in VB.NET? What
I'm trying to achieve is to determine at runtime what the size
of hashtable is in terms of the memory it occupies.

Why do you need that?
 
Christopher,
As I said, the first time, there is no SizeOf operator.

Hence: No! there is no other way! The closest you can come is to iterate
over the HashTable adding up the size of each object. However you cannot get
the size of each object! plus you do not know the size that the HashTable
needs internally to implement the HashTable.

As Herfried ask, what are you attempting that you need to know the size of a
HashTable?

Hope this helps
Jay
 
I believe the VB's Len function is still implemented, maybe that will work.
Also try LenB, I'm not sure if that one is implemented.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"


: Hello Tom,
:
: Thanks for the response. You are right, the Marshal.SizeOf does not work.
Is
: there another mechanism you could think of?
:
: Thanks,
: Chris
:
: : > Try Reflection.Marshal.SizeOf, but I fear this may only return the size
of
: > the class, not the contents in memory, I'm not sure though. Give it a
try.
: >
: > --
: > HTH,
: > -- Tom Spink, Über Geek
: >
: > Please respond to the newsgroup,
: > so all can benefit
: >
: > "Maybe it's a game called 'Punish the User'"
: >
: >
: > : > : Hello All,
: > :
: > : Is there an equivalent of SizeOf operator in VB.NET? What I'm trying
to
: > : achieve is to determine at runtime what the size of hashtable is in
: terms
: > of
: > : the memory it occupies.
: > :
: > : Thanks in advance,
: > : chris
: > :
: > :
: >
: >
:
:
 
Hello,

Tom Spink said:
I believe the VB's Len function is still implemented, maybe
that will work.

'Len' doesn't work for a 'Hashtable'.

;-)
Also try LenB, I'm not sure if that one is implemented.

'LenB' is not included any more.
 
: 'Len' doesn't work for a 'Hashtable'.

All I can say is, damn hash tables

: 'LenB' is not included any more.

Mhm. Good :-)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"


: Hello,
:
: > I believe the VB's Len function is still implemented, maybe
: > that will work.
:
: 'Len' doesn't work for a 'Hashtable'.
:
: ;-)
:
: > Also try LenB, I'm not sure if that one is implemented.
:
: 'LenB' is not included any more.
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: http://www.mvps.org/dotnet
:
:
 
Back
Top