Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 1.17 KB

allocation.md

File metadata and controls

29 lines (21 loc) · 1.17 KB

Overview

  • Summary of (heap) allocation mechanisms

make function

  1. Creates slices, maps, channels
  2. returns initialized T
  3. assignment creates a new variable which points to the same storage location
    1. Similar to a reference in c++ (but not the same)
  4. returns a pointer
  5. Official docs

new function

  1. Allocates memory on heap (like calloc in c)
  2. Does NOT initialize memory
  3. Official docs

Idioms

  1. Use make 90% of the time

Other Resources

  1. https://go101.org/optimizations/0.3-memory-allocations.html
  2. make
  3. new
  4. Effective Go > make
  5. Effective Go > new