.NET equivalent of size_t

Niranjan U picture Niranjan U · Apr 21, 2009 · Viewed 7.8k times · Source

I have a piece of .NET code which I want to port to 64-bit. The codes basically is a set of P/Invoke calls to some other C dll. One of the functions in the C dll has a parameter 'size_t'. What datatype should I use in my P/Invoke signature so that the marshalling works fine. I was thinking of using a IntPtr or a UIntPtr but some say that they are a pointer equivalent thing in .NET and shouldnt be using it. Does anyone know what the correct type for this is?

Answer

Patrick McDonald picture Patrick McDonald · Apr 21, 2009

UIntPtr will work (IntPtr would probably work too, but size_t is unsigned, so UIntPtr is a better fit)

JaredPar has written something on his blog (and a follow-up) about this.