Francesco Belladonna
Francesco Belladonna

Reputation: 11709

C# sizeof object pointer (SAFE context)

Ok while sizeof(Myenum) and sizeof(int) works, I would like to use sizeof(object), but I don't want the size of the object, but the size of pointer... only for portability reason, I need to know if is a 64 bit pointer or 32 bit pointer, I can avoid using sizeof if is ok with conditional compilation, but I don't know if there are constants to check if we are on a 32 bit system instead of 64 bit

Thanks for suggestions

Upvotes: 0

Views: 4667

Answers (2)

decyclone
decyclone

Reputation: 30840

Use IntPtr.Size.

Reference : Simple way to check if you're on a 64-bit machine

Upvotes: 5

Aykut Çevik
Aykut Çevik

Reputation: 2088

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 is a pointer, found it at IntPtr Structure.

Upvotes: 0

Related Questions