I have a simple piece of code where I allocate memory for int8
, int16
, int32
and int64
types and print out the addresses of the variables:
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println(runtime.Compiler, runtime.GOARCH, runtime.GOOS)
var i8 *int8
var i16 *int16
var i32 *int32
var i64 *int64
fmt.Println(&i8)
fmt.Println(&i16)
fmt.Println(&i32)
fmt.Println(&i64)
}
Here is the output I receive:
gc amd64 darwin
0xc00008a020
0xc00008a028
0xc00008a030
0xc00008a038
From here I may conclude that only int16
is using 4 bytes, the other types are using 8 bytes.
Are both my reasoning and the method of checking the allocated memory size correct?
If yes, what would be the advantages of using int8
, int32
on a 64-bit architecture system?