如何测量Ruby对象的大小? [英] How to measure the size of a Ruby object?
问题描述
我遇到了Memcache问题,我想知道了解我创建的对象有多大的最佳方法.
I'm having Memcache problems and I was wondering what is the best way to know how big the objects I create are.
我唯一的解决方案是将它们放到Memcache中,以字节为单位显示它们的大小(顺便说一句,我可以自定义Memcache的输出吗?我希望可读的字节数……).
The only solution I have is to put them into Memcache which display their size in bytes (by the way, can I customize Memcache's output? I want readable kilobytes…).
谢谢
凯文
推荐答案
优秀的Eigenclass博客曾经有一篇有趣的文章:
The excellent Eigenclass blog had an interesting article on that once:
http: //web.archive.org/web/20120126022146/http://eigenclass.org/R2/writings/object-size-ruby-ocaml
围绕ruby-talk进行了很好的讨论,这引发了Robert Klemme(Ruby最佳实践)的一些代码:
There also was a good discussion on ruby-talk, which led to some code by Robert Klemme (Ruby Best Practices):
http://www.ruby-forum.com/topic/156648
将第一篇文章中的值放入脚本中可能会让您入门,并且可能很有教育意义.
Plugging the values from the first article into the script might get you started and is probably quite educational.
您还可以签出memprof,尽管它更多地是关于对象引用和查找内存泄漏而不是实际大小:
You could also check out memprof, though it's more about object references and finding memory leaks than actual sizes:
http://github.com/ice799/memprof
这篇关于如何测量Ruby对象的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!