From: Brian Candler Date: 2009-11-10T18:05:22+09:00 Subject: Re: Good or best way to allocate a large array Ralph Shnelvar wrote: > I will want/need to create an array of approximately 300K rows and 20 > columns. The array will be an array of either 32-bit quantities or > 64-bit quantities. > > Does Ruby support native 64-bit quantities? If you want to hold this all in RAM, then I think your most space-efficient way would be to pack each row of 20 columns into a String (of 80 or 160 bytes). You can use Array#pack and String#unpack to convert when required. val1 = 0x0102030405060708 val2 = 0xf0e0d0c0b0a09080 row = [val1, val2].pack("Q*") p row.unpack("Q*") Q* is for unsigned 64-bit. Use q* for signed 64, L* or l* for unsigned/signed 32 bit. With 32-bit there are also options for using a fixed byte ordering (little or big endian) rather than native byte ordering. Warning: take care if using ruby 1.9, because 1.9 Strings are of "characters" and not necessarily of "bytes". This may become critical if you decide to write these structures out to disk and read them back in again. Details at http://github.com/candlerb/string19/blob/master/string19.rb -- Posted via http://www.ruby-forum.com/.