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 / C++ / MFC
  4. Data types in Visual C++

Data types in Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondata-structureshelptutorial
6 Posts 5 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.
  • E Offline
    E Offline
    Eikthrynir
    wrote on last edited by
    #1

    Hi! I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue. If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue; I have created this small test program:int main( void ) { __int32 n32BitsValue = 0x64; __int16 n16BitsValue = 0x64; return 0; }
    After that, I disassembled it using dumpbin /disasm test.exe. Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:mov **dword** ptr [ebp - 4], 64h mov **word** ptr [ebp - 8], 64h
    So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable? Any help would be greatly appreciated. Thanks in advance!

    L T G H 4 Replies Last reply
    0
    • E Eikthrynir

      Hi! I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue. If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue; I have created this small test program:int main( void ) { __int32 n32BitsValue = 0x64; __int16 n16BitsValue = 0x64; return 0; }
      After that, I disassembled it using dumpbin /disasm test.exe. Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:mov **dword** ptr [ebp - 4], 64h mov **word** ptr [ebp - 8], 64h
      So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable? Any help would be greatly appreciated. Thanks in advance!

      L Offline
      L Offline
      Link2006
      wrote on last edited by
      #2

      Eikthrynir wrote:

      If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue;

      printf("n16BitsValue: %d\n", sizeof(n16BitsValue)); printf("n32BitsValue: %d\n", sizeof(n32BitsValue)); n16BitsValue: 2 n32BitsValue: 4 so yeah, 16-bit and 32-bit Also, VC sees __int16 as short, and __int32 as int.

      1 Reply Last reply
      0
      • E Eikthrynir

        Hi! I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue. If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue; I have created this small test program:int main( void ) { __int32 n32BitsValue = 0x64; __int16 n16BitsValue = 0x64; return 0; }
        After that, I disassembled it using dumpbin /disasm test.exe. Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:mov **dword** ptr [ebp - 4], 64h mov **word** ptr [ebp - 8], 64h
        So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable? Any help would be greatly appreciated. Thanks in advance!

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        Eikthrynir wrote:

        Then I realized that it allocates 32 bits on the system stack for each variable.

        Eikthrynir wrote:

        mov dword ptr [ebp - 4], 64h mov word ptr [ebp - 8], 64h

        dword is 32 bits, but word is 16 bits AFAIK, so no, not the 2 variables make 32 bits.


        TOXCCT >>> GEII power

        [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

        1 Reply Last reply
        0
        • E Eikthrynir

          Hi! I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue. If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue; I have created this small test program:int main( void ) { __int32 n32BitsValue = 0x64; __int16 n16BitsValue = 0x64; return 0; }
          After that, I disassembled it using dumpbin /disasm test.exe. Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:mov **dword** ptr [ebp - 4], 64h mov **word** ptr [ebp - 8], 64h
          So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable? Any help would be greatly appreciated. Thanks in advance!

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #4

          The compiler 'allocates' 32 bits on the stack for an __int16, but the code it generates only references the lower 16 bits. The reason for this is efficiency due to memory alignment. Modern Intel processors access memory most efficiently on 32-bit boundaries. I don't know about AMD or the other manufacturers, but I would suspect they are similar. Why is this a concern?


          Software Zen: delete this;

          Fold With Us![^]

          E 1 Reply Last reply
          0
          • G Gary R Wheeler

            The compiler 'allocates' 32 bits on the stack for an __int16, but the code it generates only references the lower 16 bits. The reason for this is efficiency due to memory alignment. Modern Intel processors access memory most efficiently on 32-bit boundaries. I don't know about AMD or the other manufacturers, but I would suspect they are similar. Why is this a concern?


            Software Zen: delete this;

            Fold With Us![^]

            E Offline
            E Offline
            Eikthrynir
            wrote on last edited by
            #5

            Thank you for your time! I really appreciate it! The reason I wanted to know how much memory the compiler "allocates" on the stack is the performance concerning space. Thanks again!

            1 Reply Last reply
            0
            • E Eikthrynir

              Hi! I have a question regarding the use of different types of integers in Visual C++ 6.0. For example, I want to use in my application an integer variable named nIntValue. If I declare it like this: __int16 nIntValue; does the system allocate it on only 16 bits or it still uses 32 bits as if I declared it: __int32 nIntValue; I have created this small test program:int main( void ) { __int32 n32BitsValue = 0x64; __int16 n16BitsValue = 0x64; return 0; }
              After that, I disassembled it using dumpbin /disasm test.exe. Then I realized that it allocates 32 bits on the system stack for each variable. So it didn't matter for the OS that I wanted n16BitsValue to be 16 bits long. The only difference I noticed was this:mov **dword** ptr [ebp - 4], 64h mov **word** ptr [ebp - 8], 64h
              So it allocated 32 bits on that stack for n16BitsValue, but modified only 16 of them. If this happens, what need is for these different integer types anyway? What can be done to force the operating system to allocate only 16 bits for an __int16 variable? Any help would be greatly appreciated. Thanks in advance!

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              And see here[^]:)


              WhiteSky


              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