Subject: Byte Arrays in Ruby
	Date: mar 31 dic 13 05:40:32 +0100

Quoting Jabari Z. (lists / ruby-forum.com):

> I have an algorithm which uses an array of boolean (True/False) data.
> I would like to conserve and extend memory use by having the array
> use less memory.
> 
> Is it possible in Ruby (2.1.0 >) to effectively create byte arrays
> so that each index (array[n]) is a byte boolean?

Maybe there is something that helps in that direction, but from what I
know, since in Ruby everything is an object, even if you were to limit
the disk occupation of the actual variable to one byte, it would then
need all the management infrastructure that each other object
requires. Thus, I think you would not save so much. 

If you are short in memory, you may create a C-coded class that
manages blocks of these bytes - say 1k or 1M - where the storage is
kept in an allocated C array. You'll access single values or ranges of
values through calls included in your C code. But when data enters
Ruby-land, I'd have it converted to Ruby integers.

The way to best code such a class would depend on your actual needs.

Carlo

-- 
  *         Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido / fluido.as             che bisogno ci sarebbe
  *               di parlare tanto di amore e di rettitudine? (Chuang-Tzu)