By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,699 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

SizeOf operator

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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'"
"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
: 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
:
:
Nov 20 '05 #2

P: n/a
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

"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #3

P: n/a
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
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

"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
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


Nov 20 '05 #4

P: n/a
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

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
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'"
"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
: 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
:
:

Nov 20 '05 #5

P: n/a
Hello,

"Christopher Pragash" <ch**********@hotmail.com> schrieb:
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?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6

P: n/a

"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
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
Nov 20 '05 #7

P: n/a
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

"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:ei**************@tk2msftngp13.phx.gbl...
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

"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
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



Nov 20 '05 #8

P: n/a
Hello,
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> schrieb:
Have you tried SizeOf( ) ?

=)

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


Have you tried it?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #9

P: n/a
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'"
"Christopher Pragash" <ch**********@hotmail.com> wrote in message
news:e#**************@TK2MSFTNGP09.phx.gbl...
: 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
:
: "Tom Spink" <th**********@ntlworld.com> wrote in message
: news:OC**************@TK2MSFTNGP12.phx.gbl...
: > 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'"
: >
: >
: > "Christopher Pragash" <ch**********@hotmail.com> wrote in message
: > news:uK**************@TK2MSFTNGP09.phx.gbl...
: > : 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
: > :
: > :
: >
: >
:
:
Nov 20 '05 #10

P: n/a
Hello,

"Tom Spink" <th**********@ntlworld.com> schrieb:
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
Nov 20 '05 #11

P: n/a
: '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'"
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:Od*************@tk2msftngp13.phx.gbl...
: Hello,
:
: "Tom Spink" <th**********@ntlworld.com> schrieb:
: > 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
:
:
Nov 20 '05 #12

P: n/a
No, I saw that it doesn't work.

=(

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> schrieb:
Have you tried SizeOf( ) ?

=)

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


Have you tried it?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


Nov 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.