0PricingLogin
Zig Academy · Lesson

alloc, free, create, destroy

The core allocator operations.

Four Core Operations

An allocator gives you four key calls: alloc and free for many items, create and destroy for a single value.

alloc Returns a Slice

Use alloc to request a run of items. You pass the element type and a count, and you get back a slice of that many elements.

const buf = try a.alloc(u8, 64);

All lessons in this course

  1. Why Zig Has No Hidden Allocations
  2. The Allocator Interface
  3. alloc, free, create, destroy
  4. Dynamic Lists with ArrayList
← Back to Zig Academy