Go manages memory by routing allocations to one of three paths based on object size: tiny (≤16 bytes), small (17–32768 bytes), or large (>32768 bytes). Tiny objects are packed into 16-byte slots to reduce waste, small objects use size-class bins for efficient reuse, and large objects bypass the allocator to request memory directly from the OS. This strategy minimizes fragmentation and garbage collection overhead.
// Example: Tiny allocation (≤16 bytes) uses packed slots
var tiny int32 // 4 bytes, fits in 16-byte slot
// Example: Small allocation (17–32KB) uses size-class bins
var small [100]byte // 100 bytes, uses nearest size class
// Example: Large allocation (>32KB) requests OS memory directly
var large [40000]byte // 40KB, bypasses allocator bins