int_ptr, long_ptr這些類型的含义

The *_PTR types were added to the Windows API in order to support Win64's 64bit addressing.

Because 32bit APIs are used to store pointers to things using data types like DWORDS, it was necessary to create new types for 64 bit compatibility that acted like a DWORD in 32bits, but were extended to 64bits when used in a 64bit app.

So, for example, application developers who want to write code that works as 32bit OR 64bit the windows 32bit API SetWindowLong(HWND,int,LONG) was changed to SetWindowLongPtr(HWND,int,LONG_PTR)`

In a 32bit build, SetWindowLongPtr is simply a macro that resolves to SetWindowLong, and LONG_PTR is likewise a macro that resolves to LONG. In a 64bit build on the other hand, SetWindowLongPtr is an API that accepts a 64bit long as its 3rd parameter, and ULONG_PTR is typedef for unsigned __int64.

By using these _PTR types, one codebase can compile for both Win32 and Win64 targets.


When performing pointer arithmetic, these types should also be used in 32bit code that needs to be compatible with 64bit.

so, if you need to access an array with more than 4billion elements, you would need to use an INT_PTR rather than an INT

  CHAR* pHuge = new CHAR[0x200000000]; // allocate 8 billion bytes
  INT idx;
  INT_PTR idx2;
  pHuge[idx]; // can only access the 1st 4 billion elements.
  pHuge[idx2]; // can access all 64bits of potential array space.
目的是为了在32位系统和64位系统保持兼容。举例来说, INT_PTR在32位系统下表示32bit的值,在64位系统下可表示64位的值。
就是这样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值