SizeOf operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Pragash

    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


  • Tom Spink

    #2
    Re: SizeOf operator

    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" <chrispragash@h otmail.com> wrote in message
    news:uKmTGN8eDH A.2248@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
    :
    :


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: SizeOf operator

      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" <chrispragash@h otmail.com> wrote in message
      news:uKmTGN8eDH A.2248@TK2MSFTN GP09.phx.gbl...[color=blue]
      > 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[/color]
      of[color=blue]
      > the memory it occupies.
      >
      > Thanks in advance,
      > chris
      >
      >[/color]


      Comment

      • Christopher Pragash

        #4
        Re: SizeOf operator

        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]" <Jay_Harlow@ema il.msn.com> wrote in message
        news:eiLxEd8eDH A.3788@tk2msftn gp13.phx.gbl...[color=blue]
        > Christopher,
        > Unfortunately due to the way objects & memory is laid out there is no[/color]
        SizeOf[color=blue]
        > 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" <chrispragash@h otmail.com> wrote in message
        > news:uKmTGN8eDH A.2248@TK2MSFTN GP09.phx.gbl...[color=green]
        > > 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[/color][/color]
        terms[color=blue]
        > of[color=green]
        > > the memory it occupies.
        > >
        > > Thanks in advance,
        > > chris
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Christopher Pragash

          #5
          Re: SizeOf operator

          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" <thomas.spink@n tlworld.com> wrote in message
          news:OC0yRc8eDH A.2236@TK2MSFTN GP12.phx.gbl...[color=blue]
          > 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" <chrispragash@h otmail.com> wrote in message
          > news:uKmTGN8eDH A.2248@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[/color]
          terms[color=blue]
          > of
          > : the memory it occupies.
          > :
          > : Thanks in advance,
          > : chris
          > :
          > :
          >
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: SizeOf operator

            Hello,

            "Christophe r Pragash" <chrispragash@h otmail.com> schrieb:[color=blue]
            > 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.[/color]

            Why do you need that?

            --
            Herfried K. Wagner
            MVP · VB Classic, VB.NET
            Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



            Comment

            • Jeremy Cowles

              #7
              Re: SizeOf operator


              "Christophe r Pragash" <chrispragash@h otmail.com> wrote in message
              news:uKmTGN8eDH A.2248@TK2MSFTN GP09.phx.gbl...[color=blue]
              > 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[/color]
              of[color=blue]
              > the memory it occupies.[/color]

              Have you tried SizeOf( ) ?

              =)

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

              HTH,
              Jeremy


              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: SizeOf operator

                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" <chrispragash@h otmail.com> wrote in message
                news:uq6ygk8eDH A.1872@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Jay,
                >
                > Thanks for the Response. I did try the Marshal.SizeOf, but as you[/color]
                mentioned[color=blue]
                > it does not work for Hashtable. Is there any other way that this could be
                > achieved?
                >
                > Thanks again,
                > Chris
                >
                > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@ema il.msn.com> wrote in[/color]
                message[color=blue]
                > news:eiLxEd8eDH A.3788@tk2msftn gp13.phx.gbl...[color=green]
                > > Christopher,
                > > Unfortunately due to the way objects & memory is laid out there is no[/color]
                > SizeOf[color=green]
                > > 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[/color][/color]
                objects.[color=blue][color=green]
                > >
                > > Hope this helps
                > > Jay
                > >
                > > "Christophe r Pragash" <chrispragash@h otmail.com> wrote in message
                > > news:uKmTGN8eDH A.2248@TK2MSFTN GP09.phx.gbl...[color=darkred]
                > > > Hello All,
                > > >
                > > > Is there an equivalent of SizeOf operator in VB.NET? What I'm trying[/color][/color][/color]
                to[color=blue][color=green][color=darkred]
                > > > achieve is to determine at runtime what the size of hashtable is in[/color][/color]
                > terms[color=green]
                > > of[color=darkred]
                > > > the memory it occupies.
                > > >
                > > > Thanks in advance,
                > > > chris
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: SizeOf operator

                  Hello,


                  "Jeremy Cowles" <jeremy.cowle s[nosp@m]asifl.com> schrieb:[color=blue]
                  > Have you tried SizeOf( ) ?
                  >
                  > =)
                  >
                  > System.Runtime. InteropServices .Marshal.SizeOf ( [Type | Object] )[/color]

                  Have you tried it?

                  --
                  Herfried K. Wagner
                  MVP · VB Classic, VB.NET
                  Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



                  Comment

                  • Tom Spink

                    #10
                    Re: SizeOf operator

                    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" <chrispragash@h otmail.com> wrote in message
                    news:e#WnEl8eDH A.1872@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" <thomas.spink@n tlworld.com> wrote in message
                    : news:OC0yRc8eDH A.2236@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" <chrispragash@h otmail.com> wrote in message
                    : > news:uKmTGN8eDH A.2248@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
                    : > :
                    : > :
                    : >
                    : >
                    :
                    :


                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: SizeOf operator

                      Hello,

                      "Tom Spink" <thomas.spink@n tlworld.com> schrieb:[color=blue]
                      > I believe the VB's Len function is still implemented, maybe
                      > that will work.[/color]

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

                      ;-)
                      [color=blue]
                      > Also try LenB, I'm not sure if that one is implemented.[/color]

                      'LenB' is not included any more.

                      --
                      Herfried K. Wagner
                      MVP · VB Classic, VB.NET
                      Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



                      Comment

                      • Tom Spink

                        #12
                        Re: SizeOf operator

                        : '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]" <hirf.nosp@m.ac tivevb.de> wrote in message
                        news:Od18mO9eDH A.576@tk2msftng p13.phx.gbl...
                        : Hello,
                        :
                        : "Tom Spink" <thomas.spink@n tlworld.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
                        :
                        :


                        Comment

                        • Jeremy Cowles

                          #13
                          Re: SizeOf operator

                          No, I saw that it doesn't work.

                          =(



                          "Herfried K. Wagner [MVP]" <hirf.nosp@m.ac tivevb.de> wrote in message
                          news:%23JxfJI9e DHA.1732@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                          > Hello,
                          >
                          >
                          > "Jeremy Cowles" <jeremy.cowle s[nosp@m]asifl.com> schrieb:[color=green]
                          > > Have you tried SizeOf( ) ?
                          > >
                          > > =)
                          > >
                          > > System.Runtime. InteropServices .Marshal.SizeOf ( [Type | Object] )[/color]
                          >
                          > Have you tried it?
                          >
                          > --
                          > Herfried K. Wagner
                          > MVP · VB Classic, VB.NET
                          > http://www.mvps.org/dotnet
                          >
                          >
                          >[/color]

                          Comment

                          Working...