Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is equal to the c++ size_t in c#

Tags:

c++

c#

wrapper

I have a struct in c++:

struct some_struct{
uchar* data;
size_t size;
}

I want to pass it between manged(c#) and native(c++). What is the equivalent of size_t in C# ?

P.S. I need an exact match in the size because any byte difference will results in huge problem while wrapping

EDIT:

Both native and manged code are under my full control ( I can edit whatever I want)

like image 925
Humam Helfawi Avatar asked Oct 02 '15 12:10

Humam Helfawi


2 Answers

You better to use nint/nuint which is wrapper around IntPtr/UIntPtr

like image 114
Timur Vafin Avatar answered Oct 24 '22 17:10

Timur Vafin


The best equivalent for size_t in C# is the UIntPtr type. It's 32-bit on 32-bit platforms, 64-bit on 64-bit platforms, and unsigned.

like image 40
Roger Sanders Avatar answered Oct 24 '22 18:10

Roger Sanders