elementPtrFrom method

MemoryPointer<R> elementPtrFrom(
  1. MemoryPointer<RType> derefedBase,
  2. int index
)

Address of element index, given a pointer value you've already dereferenced or otherwise resolved (e.g. via pointerElementPtr).

Use this instead of elementPtr whenever you're holding the actual T* value rather than the address of a pointer slot, the two are easy to conflate, and conflating them was the exact bug that motivated pulling this method out on its own.

Implementation

MemoryPointer<R> elementPtrFrom(MemoryPointer derefedBase, int index)
  => derefedBase.offsetBy(index * type.target.byteSize);