查找特定Hash在Ruby中使用的字节数 [英] Find number of bytes a particular Hash is using in Ruby

查看:70
本文介绍了查找特定Hash在Ruby中使用的字节数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的是Ruby用于特定Hash对象的字节数。如何做到这一点?

All I want to know is how many bytes Ruby is using for a particular Hash object. How do I do that?

推荐答案

在2010年GoGaRuCo上的Ruby 1.9上,我了解了一些添加到ObjectSpace的东西, 1.9这似乎是诀窍。

In tenderlove's talk on Ruby 1.9 at GoGaRuCo 2010, I learned about some stuff added to ObjectSpace in 1.9 that would seem to do the trick.

require "objspace"
obj = {some:"STUFF"}
ObjectSpace.memsize_of(obj) # => you can imagine

找到一些 docs on objspace ,但很多都是日文。

Found some docs on objspace but a lot of it is Japanese. There's some English in there if you keep looking.

仍然不确定如何使用Ruby获取1.8.7中对象的内存大小。

Still not sure how I can get the memory size of an object in 1.8.7 by using Ruby.

这篇关于查找特定Hash在Ruby中使用的字节数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆