加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 22:15:03 所属栏目:百科 来源:网络整理
导读:有什么办法在ruby获取对象的内存地址.. 说.. (i = 5)是可能获取该对象的mem地址5 .. 我一直试图得到这一段时间.., 任何答案将非常感激… 谢谢, 问候levirg 解决方法 是. 从“Fiddling with Ruby’s Fiddle”: “You can get the actual pointer value of an
有什么办法在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”可以做一些其他很酷的事情.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读