Starting from FW 4.0, the IntPtr
structure has the Add
method:
public static IntPtr Add(
IntPtr pointer,
int offset
)
Which is great, as it's supposed to address all those questions on IntPtr
math we have had (1, 2, probably more).
But why is the offset
int
?
Must it not be IntPtr
? I can easily imagine offsetting a 64-bit pointer by a value which is beyond the int
range.
For instance, consider Marshal.OffsetOf
:
public static IntPtr OffsetOf(
Type t,
string fieldName
)
It returns an IntPtr
as the offset to the structure member. Which makes perfect sense! And you cannot easily use this offset with the new Add
method. You'd have to cast it to Int64
, then call Add
several times in a loop.
Also, it seems to kill the very idea of the IntPtr.Size
being irrelevant to a properly written application. You will have to cast the offset to a particular type, such as Int64
, at which point you must start managing the size difference. And image what will happen when 128-bit IntPtr
appears.
My question here is, why?
Am I correct in my conclusions, or am I missing the point?