Why is the output of the golang unsafe.Sizeof () string 8 bytes under windows?

the following code shows that the output in a linux-like operating system is 16 bytes, which is the same as officially, but in a windows environment, the output is 8 bytes? Excuse me, why is this?

package main

import (
    "fmt"
    "unsafe"
)

func main() {
    var a = "hello world"
    fmt.Print(unsafe.Sizeof(a))
}
Jul.26,2021

you should install a 32-bit version under windows and a 64-bit version under linux, resulting in this difference. For a string, the 32-bit version will return 8-bit version and the 64-bit version will return 16.


the occupied space of a string should be a uintptr pointer plus the length of the string int , Windows32 bit version is 4x4 and Windows32 64-bit version is 8room8

Menu