I think I should get 8 when I use IntPtr.Size. However, I still get 4 on a 64-bit machine with Windows 7 x64. Why?
-
4Are you compiling your application as x86 (Properties > Build > Platform Target) rather than x64? – Rob Feb 09 '12 at 06:40
-
See here: http://stackoverflow.com/questions/399003/is-the-sizeofsome-pointer-always-equal-to-four – htmldrum Feb 09 '12 at 06:40
4 Answers
Check your file CPU architecture. Is it x86? It should be Any CPU or x64.

- 27,060
- 21
- 118
- 148

- 1,079
- 2
- 13
- 31
The 64 bit operating system implements an emulated environment known as WOW64 which emulates the 32 bit Windows environment. You are building your program targeting x86, i.e. 32 bit. That means that your process runs under the emulator as a 32 bit process and of course pointers are 4 bytes wide.
If you change your options to target x64 or AnyCPU then the pointer size will be 8 bytes when your process runs on a 64 bit system.

- 601,492
- 42
- 1,072
- 1,490
In addition to the previous answers, even if you have selected the Any CPU architecture, Visual Studio 2013 has a new option in project properties called "Prefer 32-bit". You must turn it off on 64-bit development machines to get IntPtr.Size = 8.

- 30,738
- 21
- 105
- 131

- 33,414
- 24
- 162
- 251
Check your build target: x86, x64, or Any CPU
If your configuration is x86 or Any CPU, then, the intptr is 4 maybe.
More suggestions:
If you don’t have a requirement to run your program in x64 mode, please don’t change the build target to x64, because x64 mode has negative effects on both performance and space usage. I forgot the link of the original article on MSDN, but the main reason is the increase of pointer size and GC burden, you can search that article.

- 30,738
- 21
- 105
- 131

- 404
- 2
- 11