Logo

Programming-Idioms

History of Idiom 109 > diff from v8 to v9

Edit summary for version 9 by :
New Ada implementation by user [Smaehtin]

Version 8

2016-02-16, 22:08:27

Version 9

2016-02-18, 16:58:03

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.

Code
auto n = T.sizeof;
Code
auto n = T.sizeof;
Doc URL
http://dlang.org/ctod.html#sizeof
Doc URL
http://dlang.org/ctod.html#sizeof
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.
Note that the size does not include the memory indirectly taken by the reference fields: Strings, slices, etc.
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.
Note that the size does not include the memory indirectly taken by the reference fields: Strings, slices, etc.
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/urT_arJfKk
Demo URL
http://play.golang.org/p/urT_arJfKk