Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 64-bit Ruby?

Tags:

ruby

64-bit

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.

like image 434
Jonas Elfström Avatar asked Dec 01 '09 22:12

Jonas Elfström


1 Answers

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...)

like image 194
Marc-André Lafortune Avatar answered Sep 29 '22 06:09

Marc-André Lafortune