Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ULONG_PTR Equivalent

I am having to pass a ULONG_PTR in unsafe code in C#.

I understand that the reason for ULONG_PTR is to allow for a single codebase for both 32bit and 64bit operating systems.

Is this a case for C#'s UIntPtr? Can I be confident when passing a .Net UIntPtr as an ULONG_PTR parameter?

Thanks!

like image 857
divinci Avatar asked Dec 21 '09 12:12

divinci


2 Answers

From MSDN:

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the IntPtr type is used in the common language runtime. The UIntPtr type is provided mostly to maintain architectural symmetry with the IntPtr type

Both types are capable of storing 32-bit and 64-bit pointers. The preferred type is IntPtr.

like image 189
Darin Dimitrov Avatar answered Sep 18 '22 11:09

Darin Dimitrov


Based on the MSDN description of it I would say that it should be:

The UIntPtr 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.

like image 32
Adam Gritt Avatar answered Sep 20 '22 11:09

Adam Gritt