Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find number of bytes a particular Hash is using in Ruby

Tags:

ruby

hash

byte

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

like image 231
deepthawtz Avatar asked Sep 10 '10 18:09

deepthawtz


1 Answers

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

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

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

like image 101
deepthawtz Avatar answered Nov 18 '22 06:11

deepthawtz