Data types in Visual C++
-
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! -
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!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 asshort
, and __int32 asint
. -
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!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! ]
-
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!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;
-
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;
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!
-
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!