In .net , a Long is always 8 bytes length, no matter if you are compiling it for 32 or 64 bits, this is causing me some issues with w32 API structures which expect a 8 byte length integers for 64bits and a 4 byte length for 32 bits.
(in C++ we would just use SIZE_T, for example)
So far, i started using IntPtr data type for those cases, as its length does change from 4 to 8 based on the platform, and then just use IntPtr.toInt64 to read its value as a Long.
But since my API calls are time/memory critical I'm not 100% sure that this is the best approach, so far i have noticed that, upon read of 200 values and measure the time its adding an overhead of 2-3ms using IntPtr compared to Integer/Long values.
Another option would be define 2 different structures, one as integer to be used in 32bit and other as long to be used on 64bit, but this doesn't not seems very elegant to me.
Is there any other option available to deal with this? Any Marshal data type or something that im not aware of?
And as a plus, is there any benefit as declaring Marshal.DataTypes on the structure if it not needed? (like for integers/longs) ? does it speedup anything?
Thanks for the comments and sorry for my bad English, hope i make myself clear.