How to memcopy a many pointer

Both copyForwards and @memcpy expect slices (pointer to many items and length).
Your second argument is a slice, but the first argument is a pointer.
see: Convert between pointers and slices


var args: [maxArgs]?[*:0]u8 = undefined;

args allocates an array of maxArgs slices, but does not allocate storage for the actual bytes that these slices point to.

For your use case you need to both allocate enough memory and copy the contents.
There is a function for this in allocator called dupe and if you want to copy zero terminated strings dupeZ.

dupe source code allocates memory (the allocator returns a slice) and then uses @memcpy to copy its contents.

1 Like