what is intptr?

一世执手 提交于 2019-12-22 04:19:06

问题


I didn't understand what is IntPtr, could someone explain this? thanks


回答1:


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#.




回答2:


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.




回答3:


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)




回答4:


This is about the c and c++ type intptr_t but the principle is the same. What is uintptr_t data type




回答5:


http://msdn.microsoft.com/en-us/library/system.intptr(v=VS.100).aspx#Y69




回答6:


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.



来源:https://stackoverflow.com/questions/4906152/what-is-intptr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!