Curriculum Memory Allocators (intro)
Allocators (intro)
Zig has no hidden allocations. Every dynamic alloc goes through an Allocator interface value, and you pick which. The three you meet first: page_allocator (OS page granularity, simple, no bookkeeping), FixedBufferAllocator (a slice of memory you supply, zero heap), and ArenaAllocator (deferred mass-free — drop everything on deinit). The Allocator interface is uniform: alloc, free, dupe, realloc. Pick the allocator that matches the lifetime you want.
Exercises
9 ready
01
pick one
TypeScript hides allocation completely — new Foo() just
02
pick one
When the allocation has a known maximum size and you don't
03
pick one
An ArenaAllocator wraps another allocator and tracks every
04
fill blanks
Fill the missing method name. The Allocator interface
05
fill blanks
Fill the missing method name. The Allocator interface
06
type one line
Type the missing Zig line — allocate 5 bytes via the
07
type one line
Type the missing Zig line — set up a FixedBufferAllocator
08
write a program
Write a complete Zig program that allocates a 6-byte slice
09
write a program
Write a complete Zig program that uses an ArenaAllocator