Why does an empty slice have 24 bytes?
09:25 04 Jun 2021

I'm want to understand what happens when created an empty slice with make([]int, 0). I do this code for test:

emptySlice := make([]int, 0)
fmt.Println(len(emptySlice))
fmt.Println(cap(emptySlice))
fmt.Println(unsafe.Sizeof(emptySlice))

The size and capacity return is obvious, both are 0, but the size of slice is 24 bytes, why?

24 bytes should be 3 int64 right? One internal array for a slice with 24 bytes should be something like: [3]int{}, then why one empty slice have 24 bytes?

go optimization size slice sizeof