I have this implementation in C#.
If I am not wrong, it is used to: offsetting the memory location indicated by allocatedObject by size number of bytes and converting the memory pointer to an Int64
short size = getSize();
IntPtr allocatedObject;
long posInMemory = allocatedObject.Offset(size).ToInt64();
How can I achieve this in C++: the position in memory of the IntPtr (void *allocatedObject;) and convert the memory pointer to an Int64.
Assuming you have an
int64_ttype that represents a 64bits integer, you would first cast the pointer to a pointer tochar(that by definition hassizeof = 1), then offset it by the size, then cast it again to a pointer toint64_t.That’s because you cannot do pointer arithmetics with a
voidpointer, as it has no size. Alternatively, you couldreinterpret_castthe pointer to astd::intptr_t(an integer big enough to contain any pointer), increase it by size and then cast to pointer toint64_t.