Add 64 bit offset to a pointer
Posted
by Novox
on Stack Overflow
See other posts from Stack Overflow
or by Novox
Published on 2010-04-24T16:45:27Z
Indexed on
2010/04/24
19:03 UTC
Read the original article
Hit count: 138
In F#, there's the NativePtr module, but it seems to only support 32 bit offsets for its’ add/get/set functions, just like System.IntPtr does.
Is there a way to add a 64 bit offset to a native pointer (nativeptr<'a>) in F#? Of course I could convert all addresses to 64 bit integers, do normal integer operations and then convert the result again to nativeptr<'a>, but this would cost additional add and imul instructions. I really want the AGUs to perform the address calculations.
For instance, using unsafe in C# you could do something like
void* ptr = Marshal.AllocHGlobal(...).ToPointer();
int64 offset = ...;
T* newAddr = (T*)ptr + offset; // T has to be an unmanaged type
Well actually you can't, because there is no "unmanaged" constraint for type parameters, but at least you can do general pointer arithmetic in a non-generic way.
In F# we finally got the unmanaged constraint; but how do I do the pointer arithmetic?
© Stack Overflow or respective owner