访问对象内存地址在ruby..?

有什么办法在ruby获取对象的内存地址..

说..

(i = 5)是可能获取该对象的mem地址5 ..

我一直试图得到这一段时间..,

任何答案将非常感激…

谢谢,

问候levirg

解决方法

是.

从“Fiddling with Ruby’s Fiddle”:

“You can get the actual pointer value of an object by taking the object id,and doing a bitwise shift to the left. This will give you the pointer (or memory location) of the ruby object in memory.”

使用你的例子i = 5可以像这样做:

i = 5
i_ptr_int = i.object_id << 1
=> 22

In Ruby,why does inspect() print out some kind of object id which is different from what object_id() gives?”有更多关于object_id的信息,包括对您可能会发现有用的实现的C源的简要介绍.

看看“Fiddle”可以做一些其他很酷的事情.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...