String
=> theoretical limit of 231 - 1 (32 bits) or 263 - 1 (64 bits). I want to see someone manage to allocate a string this size
Integer
=> In thesis Ruby can change the representation and have infinite values
Float
=> Usually limited by architecture. Generally between 1.7976931348623158e+308 and 2.2250738585072014e-308
Array
=> There is no theoretical limit. In practice you can’t even use near the limit. In 32 bits there is a total limit of 4GB virtual memory. You won’t be able to create one array with 231 - 1 even if each element contains only 1 byte and in Ruby as everything is reference, this is far from possible. In 64 bits if you have 263 - 1 elements, will need a lot underneath (certainly this volume is much bigger) 250EB (Exabytes). Forget it
Hash
=> essentially the same Although you need even more memory. But again, don’t worry so much about this limit, the practical limit comes first
Why the theoretical string limit is calculated as
2^(arquitetura - 1) - 1
? (now yes!)– vinibrsl
You know about the address limit, how this value is calculated, right? It’s 63 and not 64 bits because it disregards the signal. This is used in the operating system (virtual memory may even have negative value to identify whether it is in RAM or disk, but this is detail). The -1 is because it starts from 0, so the last number cannot be considered, is equal to a array. You better use a
int
than auint
, no sign numbers may behave more positive, but are difficult to deal with, especially when there is interaction with other types.– Maniero