golang-data-structures

Guide Go data structure selection and implementation with slice, map, and container internals.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/dashkan/pivox --skill golang-data-structures-dashkan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-data-structures
Source: https://github.com/dashkan/pivox/tree/main/.agents/skills/golang-data-structures
Command: npx skills add https://github.com/dashkan/pivox --skill golang-data-structures-dashkan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you choose and implement Go data structures correctly by understanding how slices, maps, arrays, and standard containers behave under the hood.

Core Features & Use Cases

  • Structure selection guidance: Decide between slices vs arrays, list vs slice, heap vs sorting, builder vs buffer based on allocation and access patterns.
  • Performance-aware internals: Understand slice capacity growth, map bucket layout, and why maps don’t shrink after deletes.
  • Correct safety patterns: Apply safe pointer usage, avoid unsafe slice/map pitfalls, and choose modern tools like slices/maps packages and weak pointers for caches.

Quick Start

Ask an AI coding agent to help you refactor a hot-path Go function by choosing the best slice/map/container strategy and explaining any allocation or aliasing risks in your current approach.

Frequently Asked Questions about golang-data-structures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do Go slices grow and why does my slice capacity not match the length?

Go slice growth involves allocating a new backing array and copying elements when capacity is exceeded, causing hidden allocation costs. Preallocating slice capacity using make avoids repeated memory allocations and copying overhead during iterative appends.

Why does my Go map not shrink after deleting keys and how do I reclaim memory?

Go maps do not shrink after deletes because internal bucket layout remains allocated for structural stability. To reclaim memory from a shrunken Go map, copy remaining key-value pairs into a newly allocated map to release the old bucket memory.

What is the best way to build a memory-efficient cache in Go using weak pointers?

The best way to build a memory-efficient Go cache is using weak pointers to allow garbage collection of unreferenced cached values. Weak pointers prevent memory leaks in caches by allowing the Go runtime to reclaim memory when no strong references remain.

When should I use unsafe pointer patterns in Go slices and maps?

Use unsafe pointer patterns in Go slices and maps only when bypassing type safety for extreme performance needs, carefully managing aliasing risks. Correct safety patterns dictate preferring standard slices and maps packages over unsafe to avoid pointer aliasing pitfalls.

How do I choose between Go slices vs arrays, or heap vs sorting for performance?

Choosing between Go slices vs arrays depends on needing dynamic growth versus fixed memory layouts, while heap vs sorting depends on access patterns like continuous retrieval versus batch processing. Selecting the right Go structure requires reasoning about allocation costs and access frequency.