title: String memory usage in Golang
body: <p>I was optimising a code using a <strong>map[string]string</strong> where the value of the map was only either "A" or "B". So I thought Obviously a <strong>map[string]bool</strong> was way better as the map hold around 50 millions elements. </p>
  
  <pre><code>var a = "a"
  var a2 = "Why This ultra long string take the same amount of space in memory as 'a'"
  var b = true
  var c map[string]string
  var d map[string]bool
  
  c["t"] = "A"
  d["t"] = true
  
  fmt.Printf("a: %T, %d\n", a, unsafe.Sizeof(a))
  fmt.Printf("a2: %T, %d\n", a2, unsafe.Sizeof(a2))
  fmt.Printf("b: %T, %d\n", b, unsafe.Sizeof(b))
  fmt.Printf("c: %T, %d\n", c, unsafe.Sizeof(c))
  fmt.Printf("d: %T, %d\n", d, unsafe.Sizeof(d))
  fmt.Printf("c: %T, %d\n", c, unsafe.Sizeof(c["t"]))
  fmt.Printf("d: %T, %d\n", d, unsafe.Sizeof(d["t"]))
  </code></pre>
  
  <p>And the result was:</p>
  
  <pre><code>a: string, 8
  a2: string, 8
  b: bool, 1
  c: map[string]string, 4
  d: map[string]bool, 4
  c2: map[string]string, 8
  d2: map[string]bool, 1
  </code></pre>
  
  <p>While testing I found something weird, why <strong>a2</strong> with a really long string use 8 bytes, same as <strong>a</strong> wich has only one letter ? </p>