I thought "100" has a specific size then "num" has the copy of "100".

var num int32 = 100

 
So in this case below, "100" is passed to the function "f" is also "4" 
bytes in total?

func main() {
>        f(100)
> }
>
 

> func f(num int32) { // num is "4" bytes
>        
> }

 
2019年1月31日木曜日 9時05分32秒 UTC+9 伊藤和也:
>
> An interger constant is "int" type and takes "8" bytes memory on 64-bit 
> system.
>
> fmt.Println(unsafe.Sizeof(100)) // 8
>> fmt.Println(reflect.TypeOf(100)) // int
>
>
> and an "int32" type value takes "4" bytes.
>
> var num int32
>> fmt.Println(unsafe.Sizeof(num)) // 4
>
>
> So in this case below, Is the memory usage "12" bytes in total? (Question 
> 1)
>
> var num int32 = 100
>>          |                  |
>>     4 bytes  +  8 bytes = 12 bytes
>
>
> and in this case below, Is the memory usage "16" bytes in total? (Question 
> 2)
> because the integer constant "100" is "8" bytes first then it's converted 
> to "int32" which is "4" bytes.
>
> var num int32 = int32(100)
>>          |                 |         |
>>    4 bytes + 4 bytes + 8 bytes = 16 bytes  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to