what is intptr?

17.5k views Asked by At

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

6

There are 6 answers

0
leppie On BEST ANSWER

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

0
David Heffernan On

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.

0
CodesInChaos On

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.

0
DVK On

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)

0
jcoder On

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