From: Sigurd Date: 2012-08-31T21:57:46+09:00 Subject: Re: Array Size in Ruby If you use ruby 1.9.2 or later you can try following approach: require 'objspace' ObjectSpace.memsize_of(array).tap do |size| array.each do |el| size += ObjectSpace.memsize_of(el) end end That you'll give you size of memory taken. But that does not take into account the size of ruby RObject internal struct that is referencing every single ruby object. It's size depends on 32/64 bit platform and packing options. My guess that it's around 128 bytes. Array less than 4 elements is embedded into RObject and takes no additional size to store(that's not related to array values per se, since they have own RObject instances) So for instance, you have array a = [1,2,3,4] The raw store space is 32 bytes(array > 3 overhead) + array RObject size, + RObject size * 4 (number of int elements) On Aug 30, 2012, at 8:10 PM, Tridib Bandopadhyay wrote: > How to find out array size of an array? > > I don't need the length but want to know how much a array takes up in > memory. > > Thanks > > Tridib > > -- > Posted via http://www.ruby-forum.com/. >