From: Robert Klemme Date: 2010-01-18T18:05:43+09:00 Subject: Re: Manipulating big hunks of data 2010/1/17 Seebs : > Is there any kind of container-like-thing in Ruby for the special case > of a large number of fixed-type-datums?  (As opposed to objects.) > > Basically, imagine that I have, for instance, a huge matrix of data. > So far as I can tell, that really means a huge selection of individual > objects, all allocated possibly using separate chunks of memory, because > they all have to be, well, objects -- they can't just be raw data.  Obviously, > using any given item in the matrix is convenient if they're all already > objects, but the storage looks like it'd be ridiculously large. > > Is this just not idiomatic in Ruby?  Is there some base class or object > type I haven't spotted yet which handles cases like this? Since everything is an object in Ruby (well, almost) I am not sure what to make of your distinction. What I often do in these situations is this unifier = Hash.new {|h,k| h[k.freeze] = k} # read or create lots of stuff item = unifier[item] That way you keep at least only one version of a set of equivalent objects. This helps of course only if you have repetitive values. Depending on your use case another approach could be to store in a single (or multiple) Strings and use #pack and #unpack. I guess this works best if your data is uniformly sized. Btw, what volume of data are we talking about? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/