Issue #13166 has been updated by jzakiya (Jabari Zakiya).


My original use case was for creating an array of data that essentially
contained ``1|0`` data to represent ``true|false`` flags.

In the C version of my program I just created an array of bytes (char)
because they are fast, and waste the least amount of memory.  Creating
a true bit_array is the most memory efficient, but is much slower than
using an array of bytes (char), and was the best trade-off for that use case.

But beyond that original use case, having a true ``Array-of-Bytes`` not only can
create a fast facsimile of a true ``bit_array/vector`` it can also be used to
efficiently store and manipulate inherently byte valued data, as I've given
examples of previously.

So given some semantics for an ``Array-of-Bytes`` I want to create arrays like:

```
arrybytes = Array8.new(n)
arrybytes = Array8.new(n,0)
arrybytes = Array8.new(n,255)
arrybytes = Array8.new 
arrybytes = [1, 0 49, 30, 126, 200, 65, 17]
arrybytes << 48 << 0 << 8
arrybytes => [1, 0 49, 30, 126, 200, 65, 17, 48, 0, 8]
arrybytes[5] => 200
arrybttes[7] = 0x20
arrybytes => [1, 0 49, 30, 126, 200, 65, 32, 48, 0, 8]
arrybytes.size => 11
```
So I want to do everything I can with a regular ``Array``, except
that its content is limited to 8-bit byte values.

I am not familiar with ``NumArray``. Can you give examples of how it
can be used to provide this similar usage?


----------------------------------------
Feature #13166: Feature Request: Byte Arrays for Ruby 3
https://bugs.ruby-lang.org/issues/13166#change-63596

* Author: jzakiya (Jabari Zakiya)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I do a lot of numerically intensive applications.
In many instances I use arrays that contain boolean data (true|false or 1|0) values.

When I create such an array like:

`data = Array.new(size, value)` or just  `data = Array.new(size)`

is it correct that the default memory unit size is that of the cpu, i.e. (32|64)-bit?

Since almost all modern cpus are byte addressable, I want to optimally use their system memory 
by being able to explicitly create arrays of byte addressable elements.

For these use cases, this wlll allow my apps to extend their memory use capacity, instead
of wasting 31|63 bit of memory on 32|64 bit cpus systems just to store a boolean value.

To be clear, I am not talking about storing "strings" or "chars" but addessable 8-bit number elements.

I have not seen this capability documented in Ruby, thus I request this feature be added to
Ruby 3, and propose the following syntax that will be backwards compatible (non conflicting).

```ruby
data = Array8.new(size, value)
```

Having explicit addressable byte arrays not only will increase memory use compactness of many
applications, this compactness will directly contribute to the Ruby 3x3 goal for performance
by allowing more data to be held entirely in cache memory when possible.

Thanks in advance for its consideratoin.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>