Is there a 64-bit Ruby?

血红的双手。 提交于 2019-12-23 10:25:13

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/1829310/is-there-a-64-bit-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!