10 Apr '17, 1am

Object ID in MRI

Object ID in MRI

Non special objects encode their object id as their address in memory + 1. The encoding code is here . Normally, to convert a C integer to a Ruby integer, the integer is shifted left, then add one. But the address of a non special Ruby object will always be divisible by 40, so we know that the last bit is 0. So this code simply changes the last bit from a 0 to a 1. Clobbering the last bit means that when Ruby side of the program see it, it will be the address of the object shifted right by one.

Full article: http://tenderlovemaking.com/2017/02/01/object-id-in-mri.html

Tweets

Ruby Under The Hood: Memory Layout of an Object

rubyflow.com 11 Apr '17, 3pm

× The Ruby and Rails community linklog Made a library? Written a blog post? Found a useful tutorial? Share it with the Rub...

Object oriented enumerations in Ruby

rubyflow.com 20 Apr '17, 10am

× The Ruby and Rails community linklog Made a library? Written a blog post? Found a useful tutorial? Share it with the Rub...