C# sizeof object pointer (SAFE context)

僤鯓⒐⒋嵵緔 提交于 2019-12-25 01:34:26

问题


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


回答1:


Use IntPtr.Size.

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




回答2:


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.



来源:https://stackoverflow.com/questions/4416415/c-sharp-sizeof-object-pointer-safe-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!