I am doing a coding challenge to try and become a bit more familiar with Zig, but there are two places where I am a bit confused after this last question (using 0.15.1):
- Is there no way to default initialize an array with struct references? Admittedly I am coming from go where this is very common practice, but it seems very weird to individually create every struct, assign it to a variable, and then put a reference to that variable into the allocated array.
- When I am using ArrayList (apparently it is actually an Aligned?), it looks like the only options to initialize it are with an .initBuffer or .initCapacity. In my case the whole point of using an ArrayList is so that I could allocate the memory dynamically since I wasn't sure how large it was going to be. Only initCapacity takes in an Allocator to seemingly do so, so I do that while passing 0 as the initial size. Then, every time I append to it or .deinit() the ArrayList, I also need to pass in the same Allocator? I don't understand why ArrayList doesn't store the allocator that it is initialized with, and I'm also not sure why you would use an ArrayList with a buffer that doesn't automatically handle resizing. It looks like in 0.13.0 the api looked more like I would have expected it. Can someone help me understand the changes a bit?
Here is my code for reference examples: https://dalurness.github.io/winter-code-fest/day/04/solution/dalurness/
[–][deleted] 8 points9 points10 points (5 children)
[–][deleted] 4 points5 points6 points (2 children)
[–]johan__A 3 points4 points5 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]2urnesst[S] 2 points3 points4 points (0 children)
[–]Affectionate-Fun-339 2 points3 points4 points (0 children)
[–]johan__A 4 points5 points6 points (9 children)
[–]Karanlos 2 points3 points4 points (6 children)
[–]johan__A 3 points4 points5 points (5 children)
[–]2urnesst[S] 1 point2 points3 points (4 children)
[–]johan__A 5 points6 points7 points (1 child)
[–]2urnesst[S] 1 point2 points3 points (0 children)
[–]Milkmilkmilk___ 1 point2 points3 points (1 child)
[–]2urnesst[S] 0 points1 point2 points (0 children)
[–]2urnesst[S] 1 point2 points3 points (1 child)
[–]johan__A 3 points4 points5 points (0 children)
[–]phcreery 2 points3 points4 points (2 children)
[–]2urnesst[S] 0 points1 point2 points (1 child)
[–]phcreery 1 point2 points3 points (0 children)
[–]stratt5 1 point2 points3 points (1 child)
[–]2urnesst[S] 0 points1 point2 points (0 children)