tags:

views:

302

answers:

1

It seems like people are compiling MRI Ruby (1.8.7) for 64-bit platforms. I've been searching and reading for a while now without really getting the answers I want. What I want to know is if any of you guys actually used more than 4GB of memory in Ruby? Is Ruby truly 64-bits if you compile it that way?

I've found comments in the source code indicating that it's not tested on 64-bits. For instance it says "BigDecimal has not yet been compiled and tested on 64 bit integer system." in the comments for BigDecimal.

It would also be interesting to know how the other implementations of Ruby do in 64-bits.

+4  A: 

MRI (both the 1.8.x and 1.9.x line) can be compiled as 64 bits.

For example, Snow Leopard comes bundled with 1.8.7 compiled as 64 bits. This can be seen in the activity monitor, or from irb by asking, for example "42.size". You'll get 8 (bytes) if it is compiled in 64 bits, 4 (bytes) otherwise.

Ruby will be able to access over 4G of ram. For example:

$ irb
>> n = (1 << 29) + 8
=> 536870920
>> x=Array.new(n, 42); x.size
=> 536870921  # one greater because it holds elements from 0 to n inclusive

Getting the last line will take a while if you don't have more than 4 G or ram because the OS will swap a lot, but even on my machine with 4 GB it works. Virtual ram size for the process was 4.02 G.

I updated the comment in the bigdecimal html file which was outdated (from march 2003...)

Marc-André Lafortune
How about storing 536870920 (4GB+8) of those 64-bits integers in memory, is that possible?
Jonas Elfström
Yes, no problem. I modified my answer accordingly.
Marc-André Lafortune
Great answer, thanks!
Jonas Elfström
FYI, I updated that obsolete comment in big_decimal.
Marc-André Lafortune
Cool, if you stretch it a little bit you could say that that makes me a Ruby contributor by association. :)
Jonas Elfström