Logo

Programming-Idioms

History of Idiom 109 > diff from v2 to v3

Edit summary for version 3 by :
[Go]Better playground code

Version 2

2015-12-29, 20:59:24

Version 3

2015-12-29, 21:03:22

Idiom #109 Number of bytes of a type

Set n to the number of bytes of a variable of type T.
This makes different sense (if any), depending on the language.

Idiom #109 Number of bytes of a type

Set n to the number of bytes of a variable of type T.
This makes different sense (if any), depending on the language.

Imports
import "reflect"
Imports
import "reflect"
Code
var t T
tType := reflect.TypeOf(t)
n := tType.Size()
Code
var t T
tType := reflect.TypeOf(t)
n := tType.Size()
Comments bubble
This run-time reflection works on a value of the type T.
Warning: for a given program, the size of a type is not the same on a 32-bit machine or a 64-bit machine.
Comments bubble
This run-time reflection works on a value of the type T.
Warning: for a given program, the size of a type is not the same on a 32-bit machine or a 64-bit machine.
Doc URL
https://golang.org/pkg/reflect/#Type
Doc URL
https://golang.org/pkg/reflect/#Type
Demo URL
http://play.golang.org/p/PX6LhYcaPZ
Demo URL
http://play.golang.org/p/urT_arJfKk