Zig in Depth: FixedBufferAllocator

  Рет қаралды 1,391

Dude the Builder

Dude the Builder

Күн бұрын

NOTE: This series only covers Zig 0.11.0! Help me create more content like this!
www.paypal.com...
Zig offers a wide range of allocators that provide different strategies for memory management. The FixedBufferAllocator provides an easy and convenient way to use code that requires an allocator while providing a fixed-size stack-allocated and fast backing store to put the data into. In this episode you'll learn how to use the FixedBufferAllocator and see when it's the best option versus other allocator types.
The code: codeberg.org/d...
Relevant Links:
- ziglang.org/do...
- ziglang.org/do...

Пікірлер: 9
@bjorn2625
@bjorn2625 4 ай бұрын
Are you able to explain the logic behind .init’in an allocator and then having to get to the actual allocator by calling .allocator(). Why not have the mother struct be the real allocator?
@dudethebuilder
@dudethebuilder 4 ай бұрын
Actually, there's a video further down the playlist that explains how Interfaces can be implemented in Zig. The method explained in that video is precisely the one used by the standard library Allocator interface. In brief, the struct that you call init on is an implementing struct, but only by calling its allocator method do you obtain the actual implementation of the Allocator interface for that struct type. Sounds confusing but when you watch that video you'll see why this is.
@bjorn2625
@bjorn2625 4 ай бұрын
@@dudethebuilder great thank you, I shall look forward to that. It smells a bit like dependency injection, but still can’t wrap my head around it completely.
@kyp0717
@kyp0717 8 ай бұрын
Thank you!
@vryder
@vryder 8 ай бұрын
Is FixedBufferAllocator alloc thread safe?
@dudethebuilder
@dudethebuilder 8 ай бұрын
No, but you can wrap any allocator with a std.heap.ThreadSafeAllocator to make it thread safe: var tsa = std.heap.ThreadSafeAllocator{ .child = fba.allocator() }; const allocator = tsa.allocator();
@vryder
@vryder 8 ай бұрын
@@dudethebuilder Nice, thanks for the info!
@RobertVoogdgeert
@RobertVoogdgeert 8 ай бұрын
Running zig 0.12.0-dev.1836+dd189a354 I get errors in every exercise in which tests are used. Also this one Build Summary: 2/5 steps succeeded; 1 failed test transitive failure ├─ run test cached │ └─ zig test Debug native cached 57ms MaxRSS:13M └─ run test transitive failure └─ zig test Debug native failure Is this because I start out with zig init, which creates the zig.build, zig.build.zon, etc. (which I all leave untouched)? Zig run main.zig runs fine, but zig build test always runs into errors. Any idea what might cause this?
@dudethebuilder
@dudethebuilder 8 ай бұрын
I'm pretty sure it has to be changes between Zig 0.11.0 and the version you're running. A lot of changes have already been merged into the 0.12 development branch (master) so it wouldn't surprise me that something in the testing framework has changed. That's why I'm sticking to Zig 0.11 stable for the entire course because it would have been too much of a moving target to try it with 0.12 master.
Zig in Depth: ArenaAllocator
20:40
Dude the Builder
Рет қаралды 1,5 М.
Zig in Depth: Working with C
22:51
Dude the Builder
Рет қаралды 1,8 М.
Glow Stick Secret Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 19 МЛН
So Cute 🥰
00:17
dednahype
Рет қаралды 46 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 208 МЛН
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 85 М.
Zig Master: Slices
25:25
Dude the Builder
Рет қаралды 836
You CAN do error payloads in zig
12:26
E-xyza
Рет қаралды 1,9 М.
Zig Master: Memory in Practice
20:45
Dude the Builder
Рет қаралды 1 М.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Ryan Fleury
Рет қаралды 38 М.
Zig Master: Single Item Pointer
18:02
Dude the Builder
Рет қаралды 642
Zig Master: Introduction to Allocators
34:19
Dude the Builder
Рет қаралды 1,7 М.
Zig Master: Memory Alignment
10:00
Dude the Builder
Рет қаралды 643
Zig Master: Structs
22:57
Dude the Builder
Рет қаралды 990
Tips and tricks for reading unfamiliar code
24:30
Ants Are Everywhere
Рет қаралды 4,8 М.
Glow Stick Secret Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 19 МЛН