473,387 Members | 1,621 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,387 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 36418
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.