473,785 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 36655
Try Reflection.Mars hal.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'"
"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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

"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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********@ema il.msn.com> wrote in message
news:ei******** ******@tk2msftn gp13.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

"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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**********@n tlworld.com> wrote in message
news:OC******** ******@TK2MSFTN GP12.phx.gbl...
Try Reflection.Mars hal.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'"
"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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,

"Christophe r Pragash" <ch**********@h otmail.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

"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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

"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uq******** ******@TK2MSFTN GP09.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********@ema il.msn.com> wrote in message news:ei******** ******@tk2msftn gp13.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

"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:uK******** ******@TK2MSFTN GP09.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.cowle s[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'"
"Christophe r Pragash" <ch**********@h otmail.com> wrote in message
news:e#******** ******@TK2MSFTN GP09.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**********@n tlworld.com> wrote in message
: news:OC******** ******@TK2MSFTN GP12.phx.gbl...
: > Try Reflection.Mars hal.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'"
: >
: >
: > "Christophe r Pragash" <ch**********@h otmail.com> wrote in message
: > news:uK******** ******@TK2MSFTN GP09.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2539
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
1415
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 : size of val = 2, val = 5
5
2238
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. >> One soluton is that if the pointer to the data is given then even if we don't know the type we cn just increment the pointer and see by how much it is incremented as the c compiler itself increments it according to its size.
12
1887
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 assume that the interpreter does conform to the range values for, say, type int, but allocates storage for the variables based on their value. So, for two variables foo and bar int foo = 0; /* interpreter allocates two bytes */ int bar =...
12
2422
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
7613
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
17181
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 implementation as macro is as below #define sizeof_op1(val) (&val +1 ) - &val // for variable ex
6
2641
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 this one. Below is the code fragment. Granted it's pretty platform specific. typedef struct hwata_info_tag
9
15287
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 dynamic data( pointers). So if i have some way to overload the sizeof operator I can calculate the exact size and return.
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.