Pointer ops consistent naming

There are currently many different names for pointer operations, some of which are missing. This is a proposed unified naming scheme.

deinit existing init copy/move source(val/ptr) count(1/n) current proposed
X V move val 1 Pointer.unsafe_write(val^) same
X V copy val 1 Pointer.unsafe_write(copy=val) same
X V copy val n Bytes only std.memory.unsafe_memset Pointer.unsafe_write(copy=val, count=n)
X V move ptr 1 Pointer.unsafe_write_move_from(src) Pointer.unsafe_write_from(move=src)
X V copy ptr 1 Pointer.unsafe_write(copy=src[]) Pointer.unsafe_write_from(copy=src)
X V move ptr n std.memory.unsafe_uninit_move_n(dest, src, count=n) Pointer.unsafe_write_from(move=src, count=n)
X V copy ptr n std.memory.unsafe_uninit_copy_n(dest, src, count=n) Pointer.unsafe_write_from(copy=src, count=n)
V V move val 1 ptr[] = val^ also Pointer.unsafe_replace(val^, deinit_with?)
V V copy val 1 ptr[] = val also Pointer.unsafe_replace(copy=val, deinit_with?)
V V copy val n ? Pointer.unsafe_replace(copy=val, count=n, deinit_with?)
V V move ptr 1 ? Pointer.unsafe_replace_from(move=src, deinit_with?)
V V copy ptr 1 ? Pointer.unsafe_replace_from(copy=src, deinit_with?)
V V move ptr n ? Pointer.unsafe_replace_from(move=src, count=n, deinit_with?)
V V copy ptr n ? Pointer.unsafe_replace_from(copy=src, count=n, deinit_with?)
V X - - 1 Pointer.unsafe_deinit_pointee()/Pointer.unsafe_deinit_pointee_with() Pointer.unsafe_deinit_pointee(deinit_with?)
V X - - n std.memory.unsafe_destroy_n(ptr, count=n) Pointer.unsafe_deinit_pointee(count=n, deinit_with?)
  • Having multiple names (methods & free functions) for similar operations increases the mental overhead of remembering them.
  • deinit & init together can be done more efficiently in a single loop or specialized for trivial types.
  • Trivial types can be handled efficiently.
  • Can be overloaded on Bytes / Simd for memset fill operations.
  • Overloaded deinit_with methods supporting Linear types.
  • MAX’s can add Extension(Pointer) providing parallel equivalents.
1 Like