Why is it important to assum开发者_C百科e that integers in our computer model have a fixed size?
Because in computer math, a+1 < a can be true!
If a is a signed one-byte twos-complement value, it can store numbers from -256 to 255. If a=255, then a+1=-256.
To account for overflow errors.
Do you mean 'assume' or 'know' ?
By the fact that they are fixed size, they are limited to the quantities that they can store. Are you storing a count greater than 65,535 (unsigned 2-byte short), or the population of the Earth (6 billion - greater than a 4-byte unsigned int can store). What you're trying to model will dictate what size of datatype you use.
You can use objects that aren't fixed-size (e.g. BigInteger in Java). The downside is that performance will suffer to some degree.
An address have a fixed size which is determined by the Operating System and that's an integer number.
EDIT:
It is important to know how much memory is stored for them when you are micro optimizing. Also, we must not forget the phenomenon of number overflowing...
加载中,请稍侯......
精彩评论