I understand that int
and uint
are 64bit signed / unsigned integers - just like int64
/ uint64
. And I also understand that int
is not simply an alias for int64
(like byte
-> uint8
is), so int64
would need to be converted to int
and visa versa when applicable. However what are the benefits of using one over the other? Is there any run time performance penalty for using the general types?
Sorry if this is a common question - I had Googled for the answer (and searched on here too) as I'd have thought others might have cropped up before but didn't find anyone answer the question in terms of how they affect performance (if at all), memory usage (I'm guessing not if they're both 64bit integers?) nor how the compiler treats them.
edit: I'm aware that int
/ unit
are 32bit on 32bit architectures. For the sake of brevity and comparing like for like, I was assuming this is a 64bit Golang environment.
int is one of the available numeric data types in Go used to store signed integers. int64 is a version of int that only stores signed numeric values composed of up to 64 bits.
Int64 is used to represents 64-bit signed integers . UInt64 is used to represent 64-bit unsigned integers.
uint means “unsigned integer” while int means “signed integer”. Unsigned integers only contain positive numbers (or zero).
The types int8 , int16 , int32 , and int64 (and their unsigned counterparts) are best suited for data. An int64 is the typical choice when memory isn't an issue.
int
and uint
are only 64-bit on 64-bit architectures. On 32-bit architectures they are 32 bits.
The general answer is that, unless you need a certain precision, sticking with datatypes that are the same size as a word on the current architecture (e.g. 32 bits on a 32-bit architecture) is typically slightly more efficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With