NativeInt is just an integer, the same as a pointer. Hence the fact that it changes size on different platforms. The documentation states that:
The size of NativeInt is equivalent to the size of the pointer on the current platform.
The main use of NativeInt is to store things like operating system descriptors that are actually behind the scenes memory addresses. You should not use it to perform arithmetic operations, store arrays, etc. If you try to do this, it will be much more difficult for you to use the code between the 32-bit and 64-bit versions of your program.
You can think of Delphi NativeInt as a direct equivalent to the .net IntPtr type. In C and C ++, OS descriptor types are usually declared as void* , which is a pointer type, not an integer type. However, you would be fine using a type like intptr_t if you want.
You use the term "native integer" to describe NativeInt , but despite the name, it is very important to understand that NativeInt not a native integer type of language. It will be an Integer . Native in NativeInt refers to the underlying hardware platform, not the language.
The type Delphi Integer , a native integer, matches the type C int , the native type of the corresponding language. And on Windows, these types have 32 bits for 32 and 64-bit systems.
When Windows designers started working with 64-bit Windows, they had a lot of memory about what happened when the int changed from 16 to 32 bits when switching from 16-bit to 32-bit systems. It was not at all fun, although it was the right decision. This time, from 32 to 64, there was no good reason to make an int 64-bit type. If Windows designers did this, it would make porting a lot more difficult. And so they decided to leave int as a 32-bit type.
In terms of performance, the AMD64 architecture was designed to work efficiently with 32-bit types. Since a 32-bit integer is half that of a 64-bit integer, memory usage is reduced, making int only 32 bits in a 64-bit system. And that will have a performance advantage.
A few comments:
- You state that "C has only 64 bit pointers." This is not true. A 32-bit C compiler typically uses a flat 32-bit memory model with 32-bit pointers.
- You also say: "in Delphi
NativeInt size is 64 bits." Again, this is not so. It can be 32 or 64 bits depending on the target.