Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
25
Task/Variable-size-Get/Go/variable-size-get-2.go
Normal file
25
Task/Variable-size-Get/Go/variable-size-get-2.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// unsafe.Sizeof returns the size in bytes.
|
||||
var i int
|
||||
fmt.Println(unsafe.Sizeof(i))
|
||||
// The size returned is that of the top level object and does not
|
||||
// include any referenced data. A type like string always returns
|
||||
// the same number, the size of the string header.
|
||||
fmt.Println(unsafe.Sizeof("Rosetta"))
|
||||
fmt.Println(unsafe.Sizeof("Code"))
|
||||
// For some untrusted environments, package unsafe is not available
|
||||
// but reflect is. The Size method of a type will return the same value
|
||||
// as unsafe.Sizeof.
|
||||
fmt.Println(reflect.TypeOf("Cod").Size())
|
||||
// Some sizes are implementation dependent.
|
||||
fmt.Println(runtime.Version(), runtime.GOARCH)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue