Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. sizeof struct with array

sizeof struct with array

Scheduled Pinned Locked Moved C#
data-structureshelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ronenb
    wrote on last edited by
    #1

    Hi I would like to define a struct with array of int I define the struct as below The problem is that when I want to get the size of the struct, i'm getting it without the array size such as sNDIS_802_16E_ACTIVE m_NDIS_802_16E_ACTIVE; m_NDIS_802_16E_ACTIVE = new sNDIS_802_16E_ACTIVE(20,20); int size = Marshal.SizeOf(m_NDIS_802_16E_ACTIVE); public struct sNDIS_802_16E_ACTIVE { public UInt32 NaplistLength; public UInt32[] Nap; public UInt32 NsplistLength; public UInt32[] Nsp; public byte [] aaa; public sNDIS_802_16E_ACTIVE(UInt32 maxNSP_NAPSize, UInt32 maxNSP_NAPsize) { Nap = new UInt32[maxNSP_NAPSize]; Nsp = new UInt32[maxNSP_NAPSize]; NaplistLength = 0; NsplistLength = 0; } } ; please advice ronen

    L 1 Reply Last reply
    0
    • R Ronenb

      Hi I would like to define a struct with array of int I define the struct as below The problem is that when I want to get the size of the struct, i'm getting it without the array size such as sNDIS_802_16E_ACTIVE m_NDIS_802_16E_ACTIVE; m_NDIS_802_16E_ACTIVE = new sNDIS_802_16E_ACTIVE(20,20); int size = Marshal.SizeOf(m_NDIS_802_16E_ACTIVE); public struct sNDIS_802_16E_ACTIVE { public UInt32 NaplistLength; public UInt32[] Nap; public UInt32 NsplistLength; public UInt32[] Nsp; public byte [] aaa; public sNDIS_802_16E_ACTIVE(UInt32 maxNSP_NAPSize, UInt32 maxNSP_NAPsize) { Nap = new UInt32[maxNSP_NAPSize]; Nsp = new UInt32[maxNSP_NAPSize]; NaplistLength = 0; NsplistLength = 0; } } ; please advice ronen

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      the size of

      public struct sNDIS_802_16E_ACTIVE {
      public UInt32 NaplistLength;
      public UInt32[] Nap;
      public UInt32 NsplistLength;
      public UInt32[] Nsp;
      public byte [] aaa;
      }

      is 20B on Win32, i.e. 4B for each of the two ints, and 4B for each of the 3 arrays (an array is just a reference, not the data; the data sits elsewhere). :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      R 1 Reply Last reply
      0
      • L Luc Pattyn

        the size of

        public struct sNDIS_802_16E_ACTIVE {
        public UInt32 NaplistLength;
        public UInt32[] Nap;
        public UInt32 NsplistLength;
        public UInt32[] Nsp;
        public byte [] aaa;
        }

        is 20B on Win32, i.e. 4B for each of the two ints, and 4B for each of the 3 arrays (an array is just a reference, not the data; the data sits elsewhere). :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        R Offline
        R Offline
        Ronenb
        wrote on last edited by
        #3

        Hi But I define the size of the array size in the constructor Should the size of the member of the struct include array definitions? Ronen

        L 1 Reply Last reply
        0
        • R Ronenb

          Hi But I define the size of the array size in the constructor Should the size of the member of the struct include array definitions? Ronen

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I don't understand your question. In THAT struct, under Win32, each member takes 4 bytes, either for an int value, or for a reference. The size of the arrays themselves is irrelevant inside the struct, as they are separate objects. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          R 1 Reply Last reply
          0
          • L Luc Pattyn

            I don't understand your question. In THAT struct, under Win32, each member takes 4 bytes, either for an int value, or for a reference. The size of the arrays themselves is irrelevant inside the struct, as they are separate objects. :)

            Luc Pattyn


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            R Offline
            R Offline
            Ronenb
            wrote on last edited by
            #5

            I see OK Thanks Ronen

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups