什么是 intptr?
我不明白 IntPtr 是什么,有人可以解释一下吗? 谢谢
I didn't understand what is IntPtr, could someone explain this?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我不明白 IntPtr 是什么,有人可以解释一下吗? 谢谢
I didn't understand what is IntPtr, could someone explain this?
thanks
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
它是
void*
的托管对应项。您可以在
void*
之间进行转换,以便在托管代码中使用,而不必求助于托管层中的不安全代码(例如 C#)。It is the managed counterpart of
void*
.You can cast to and from
void*
for usage in managed code without having to resort to unsafe code in managed layers, eg C#.它是一个与指针大小相同的整数。 32 位图像中为 32 位宽,64 位图像中为 64 位宽。
It is an integer that is the same size as a pointer. 32 bits wide in 32 bit images, 64 wide in 64 bit images.
它是特定于 .NET 平台的类型,用于表示指针或句柄。
IntPtr 类型被设计为一个整数,其大小是特定于平台的。也就是说,此类实例在 32 位硬件和操作系统上预计为 32 位,在 64 位硬件和操作系统上预计为 64 位。
IntPtr 类型可由支持指针的语言使用,并且可以作为在支持和不支持指针的语言之间引用数据的通用方法。
IntPtr 对象也可用于保存句柄。例如,IntPtr 的实例在 System.IO.FileStream 类中广泛使用来保存文件句柄。
(来自 MSDSN)
It's a .NET platform-specific type that is used to represent a pointer or a handle.
The IntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.
The IntPtr type can be used by languages that support pointers, and as a common means of referring to data between languages that do and do not support pointers.
IntPtr objects can also be used to hold handles. For example, instances of IntPtr are used extensively in the System.IO.FileStream class to hold file handles.
(from MSDSN)
这是关于 c 和 c++ 类型 intptr_t 但原理是相同的。
什么是 uintptr_t 数据类型
This is about the c and c++ type intptr_t but the principle is the same.
What is uintptr_t data type
http://msdn.microsoft。 com/en-us/library/system.intptr(v=VS.100).aspx#Y69
http://msdn.microsoft.com/en-us/library/system.intptr(v=VS.100).aspx#Y69
一个指针大小的黑匣子。有时您的语言不支持不安全代码/指针,因此需要在 API 中使用 IntPtr。
我认为自 .net 2 以来它的使用已经减少,因为它的许多用例更适合安全句柄。
A pointer sized blackbox. Sometimes you have languages that don't support unsafe code/pointers, and thus need to use IntPtr in the API.
I think its use has been reduced since .net 2 since many of its use-cases are better fit for safe-handles.