有什么办法在ruby获取对象的内存地址..
说..
(i = 5)是可能获取该对象的mem地址5 ..
我一直试图得到这一段时间..,
任何答案将非常感激…
谢谢,
问候levirg
@H_301_14@解决方法
是.
从“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”可以做一些其他很酷的事情.
@H_301_14@ @H_301_14@