473,246 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

SizeOf operator

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
12 36345
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
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
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
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
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

"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
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
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
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
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
: '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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: junky_fellow | last post by:
Consider the following piece of code: #include <stddef.h> int main (void) { int i, j=1; char c; printf("\nsize =%lu\n", sizeof(i+j));
5
by: Tarun | last post by:
Hi All, I have written the following prog. int main() { int val = 4; printf("size of val = %d, val = %d",sizeof(++val),val); } output: size of val = 2, val = 4 The output expected was :...
5
by: Aloo | last post by:
dear fellas, this is anupam aka aloo and i have small problem the problem ststes :-- >> IMPLEMENT THE 'sizeof' OPERATOR IN C. i.e find the size of any data without using 'sizeof' operator. ...
12
by: ozbear | last post by:
If one were writing a C interpreter, is there anything in the standard standard that requires the sizeof operator to yield the same value for two different variables of the same type? Let's...
12
by: sonu | last post by:
#include<stdio.h> main() { int x=10,y; y=sizeof(++x); printf("x=%d\ny=%d\n",x,y); } Oput Put
8
by: Mallesh | last post by:
Can anybody tell me how sizeof operator internally implemented. In my project i want to implemnent my own sizeof operator function (like mysizeof). How i can write the code? Please help me.
4
by: vijay | last post by:
hi, if you see assembly then sizeof operator has sizeof(type) or sizeof(variable) at compile time. How does C compiler gets value at compiler time.? How can we implement sizeof operator? the...
6
by: Daniel Rudy | last post by:
Hello Everyone, I've ran into a little snag with the sizeof operator. Can you get the size of a member inside a struct using sizeof? I looked through the FAQ and I couldn't find the answer to...
9
by: Faisal | last post by:
Hi, Why C++ doesn't allow overloading of size of operator. I think it would be much handy to check the type userdefined types. For eg. In my project, I've some structures which contains...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.