#How to copy an item from a slice without assigning it to a new variable
1 messages · Page 1 of 1 (latest)
Zig doesn't have runtime string concatenation. It doesn't really have a string type at all. To build a new string from parts, a fixed buffer or an arraylist are what you'd use.
Whats a fixed buffer?
Looks like a type of allocator, not sure if that's exactly what I need here? I'll try and hack around with an arraylist to work out what I need here
Also see std.mem.concat
Arraylist is a very general solution, and more easily refactorable, but concat should just work
But yeah, you don't get a free lunch when it comes to dynamic memory
That looks like exactly what I'll need
and the doc page has example usage!? I didn't think there were any examples of how to use zig in the docs... that's great
Sure, there'll surely be examples
But pro tip: reading the source code, and the tests in the source code, is the best source of examples
There doesn't appear to be an example for https://ziglang.org/documentation/master/std/#std.process.execve, not tests (if I click the "src" in the top, then CTRL+F for "execve", the only thing that comes up is the actual function, who's source code is already on that page, and doesn't really help me understand what it needs)
I'd argue showing the test on the documentation page is more useful than showing the source code
for a sys call like execve, I think most people look at the man page for the sys call. Mapping to Zig is usually pretty straightforward.
Fair enough, that makes sense
Wait, so this only returns an error. So, how do I get the output. I have to do something with the allocator?
The output?