# New to Zig, and systems programming. What am I doing wrong here?

**URL:** <https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971>\
**Category:** Help\
**Tags:** memory-management, standard-library\
**Created:** [October 15, 2026, 12:21am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971 "2026-10-15T00:21:12Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![SuXYIO](https://ziggit.dev/user_avatar/ziggit.dev/suxyio/32/10366_2.png) [@SuXYIO](https://ziggit.dev/u/SuXYIO)\
**Post date:** [October 18, 2026, 8:09am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/21 "2026-10-18T08:09:51Z")

</div>

> [@tholmes](#):
>
> ```zig
> const alc = init.gpa;
> const io = init.io;
> 
> ```

Dunno if you noticed, that tholmes’s reply used a different allocator (you were initially using `std.heap.page_allocator`, which is fine).

Zig `init` gives you a default allocator, and the best feature is that it can detect **leaks** (forgetting to free) and **double frees** (freed twice), which’ll be helpful for learning and building!

---

<div class="post-metadata">

**Author:** ![makro](https://ziggit.dev/user_avatar/ziggit.dev/makro/32/10507_2.png) [@makro](https://ziggit.dev/u/makro)\
**Post date:** [October 18, 2026, 1:49pm UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/22 "2026-10-18T13:49:43Z")

</div>

Indeed, details matters (in zig), even if not leak, but possible leak in edge case. Moving defer to top and list appends in bottom was a bit afterthought, focus being in alloc and mem copy. Great feedback as this also emphasizes my original point to learn properly mem allocations/frees, mem copies and list functions usage before trying to get into more complex things, with Io, and other tasks where one needs to catch data.

C-code I used over decade ago, didn’t have same ensure and assume methods, so even if I knew about those in zig, good reminder to be extra careful with any ad-hoc code written too - this was “new to zig…” topic after all, so good to cover details for learning purposes. Thanks.

---

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [October 19, 2026, 2:55am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/23 "2026-10-19T02:55:15Z")

</div>

> [@makro](#):
>
> learn properly mem allocations/frees, mem copies and list functions usage before trying to get into more complex things, with Io, and other tasks where one needs to catch data.

Could you recommend some materials about that? I noticed that what stopped me go deeper is exactly the mem-related knowledge I missed: e.g., I don’t know why FixBufferAllocator needs a buffer at stack for a heap allocation, how `std.process.Init.gpa` holds on the things such that I don’t have to do `deinit()` manually, or in this thread, who owns the memory when there are several locations that store the data, `stdout_buffer`, `stdin_buffer`, instance of `std.ArrayList`, etc. I want to deepen my understanding of low-level stuffs and that’s why I’m also be doing “rewrite” C projects in Zig (for learning purpose). Any suggestion is appreciated!

---

<div class="post-metadata">

**Author:** ![ilovapples](https://ziggit.dev/user_avatar/ziggit.dev/ilovapples/32/8327_2.png) [@ilovapples](https://ziggit.dev/u/ilovapples)\
**Post date:** [October 19, 2026, 4:46am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/24 "2026-10-19T04:46:26Z")

</div>

If you have [ZLS](https://github.com/zigtools/zls) installed, you should be able to check a function’s doc comments to see its behavior. For example, most/all methods on `Io.Reader` have doc comments explaining their exact modifications to the reader’s state and/or whether they invalidate previous slices into the buffer.  
Dedicated standard library documentation is currently a bit lacking, but for now a decent resource is the standard library tests, such as [the tests for `std.heap.FixedBufferAllocator`](https://codeberg.org/ziglang/zig/src/branch/master/lib/std/heap/FixedBufferAllocator.zig#L240-L311). If you haven’t already seen it, [the official Ziglang site](https://ziglang.org/learn/) also has a nice overview of learning resources.  
Also, `FixedBufferAllocator` does not perform heap allocation; it acts as a bump allocator backed by the provided buffer, regardless of whether that buffer was itself originally allocated from stack, heap, or a raw memory region (on freestanding systems). When the buffer is full, it just throws an `error.OutOfMemory` and won’t try to allocate anything new.

---

<div class="post-metadata">

**Author:** ![Chaz](https://ziggit.dev/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@Chaz](https://ziggit.dev/u/Chaz)\
**Post date:** [October 19, 2026, 4:56am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/25 "2026-10-19T04:56:14Z")

</div>

I’ll try to help on the first one: FixedBufferAllocator **is** an allocator and is **backed by** a fixed buffer. So you need a buffer before you call .init(). One easy way to get such a buffer is to declare a buffer on the stack, which is useful because it’s super fast (as long as you can handle a comptime-known limit on the max size you’ll need before it starts returning .OutOfMemory errors and nothing needs to outlive this function call). But actually FBA doesn’t care where it is and you could also have gotten it from the heap via some other allocator instead.

---

<div class="post-metadata">

**Author:** ![pzittlau](https://ziggit.dev/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pzittlau](https://ziggit.dev/u/pzittlau)\
**Post date:** [October 19, 2026, 6:32am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/26 "2026-10-19T06:32:26Z")

</div>

I think what finally made it click is the deep realization that it’s all just bytes and everything that comes with that. But this is, I think, something that can’t easily be taught and is more such a thing that everyone needs to realize themselves. Just saying it over and over likely doesn’t help and for me it was understanding more of the underlying things(like computer architecture and operating systems) that finally did it.

I’ve heard good things about [OSTEP](https://pages.cs.wisc.edu/~remzi/OSTEP/) and that it’s quite approachable for most people who’ve done programming before; though I’ve only taken a glance at it.

---

<div class="post-metadata">

**Author:** ![WeeBull](https://ziggit.dev/user_avatar/ziggit.dev/weebull/32/6828_2.png) [@WeeBull](https://ziggit.dev/u/WeeBull)\
**Post date:** [October 26, 2026, 9:56pm UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/27 "2026-10-26T21:56:21Z")

</div>

> [@pzittlau](#):
>
> I think what finally made it click is the deep realization that it’s all just bytes and everything that comes with that. But this is, I think, something that can’t easily be taught and is more such a thing that everyone needs to realize themselves

For those of a certain generation, we started with the bytes. Or at least, it wasn’t very long before we ran into them. There just weren’t many layers to dig through. Now, there’s so many ways to write code without ever needing to worry about how the computer _actually works_ that people can go their whole careers without understanding how involved a simple program reading strings from the user really is.

It’s a real shame there aren’t any pre-virtual-memory machines around these days for people to learn on. Something with decent software on it, rather than just a microcontroller. There’s just no way to replicate the progression I had through 6502, Z80 and 68000 based machines that had all the tools you needed to make anything you wanted (paint programs, compilers, debuggers) and thriving communities around them.

---

<div class="post-metadata">

**Author:** ![mattnite](https://ziggit.dev/user_avatar/ziggit.dev/mattnite/32/5666_2.png) [@mattnite](https://ziggit.dev/u/mattnite)\
**Post date:** [October 27, 2026, 3:36am UTC](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971/28 "2026-10-27T03:36:27Z")

</div>

That’s a deep pull, very good

[Previous page](https://ziggit.dev/t/new-to-zig-and-systems-programming-what-am-i-doing-wrong-here/17971.md?page=1)
