1111
1212# BoolArray
1313
14- Arduino library for compact array of booleans of max size 2000 (UNO).
14+ Arduino library for compact array of booleans of max size 10000 (UNO R3 ).
1515
1616
1717## Description
1818
1919The BoolArray class allows the user to instantiate an array of booleans, allocating only one bit per element.
2020For example one could create an array of 1000 throws with a coin. Normally this would take 1000 bytes,
21- but BoolArray can store one throw in 1 bit, so 1000 throws in approx 125 bytes.
21+ but BoolArray can store one throw in 1 bit, so store the 1000 throws in approx 125 bytes.
2222
2323The class is optimized for storage by packing 8 elements of the array in one byte.
2424You need to check if your application needs more performance than this library can deliver.
2525
26- #### Notes
26+ ### Notes
2727
2828The BoolArray class allocates dynamic memory.
2929The ** BOOLARRAY_MAXSIZE** is set to 10000 (booleans).
30- This number is chosen as it is about the maximum one can allocate in one call on an UNO.
30+ This number is chosen as it is about the maximum one can allocate in one call on an UNO R3 .
3131
3232If one want to allocate more booleans, adjust the ** BOOLARRAY_MAXSIZE** .
3333This can be done as a command line option.
3434
3535The library is tested on AVR architecture only.
3636
3737
38- #### BoolArray32
38+ ### BoolArray32
3939
4040Since 0.3.0 a ** BoolArray32** class is added - ** experimental** for now.
4141
@@ -49,7 +49,7 @@ that are native 32 bit (not verified yet).
4949On an Arduino UNO the ** BoolArray32** class is slower.(verified).
5050
5151
52- #### Related
52+ ### Related
5353
5454The BitArray library is one from a set of three:
5555
@@ -62,29 +62,31 @@ BoolArray is faster than BitArray as it only supports single bits and does not n
6262of different bytes to read/write a value. However BoolArray currently only supports 2000 bits while
6363BitArray can support more.
6464
65+
6566## Performance
6667
67- See ** boolArrayDemo0.ino**
68+ Run ** boolArrayDemo0.ino** to get your boards figures.
6869
6970Indicative performance figures.
7071
7172| class | function | UNO | ESP32 | Notes |
7273| :--------------| :-----------:| :-------:| :--------:| :--------:|
73- | BoolArray | set(0) | 10.37 | |
74- | BoolArray | set(1) | 10.25 | |
75- | BoolArray | get(i) | 16.03 | |
76- | BoolArray | setAll(0) | 96 | | per 2000
77- | BoolArray | setAll(1) | 100 | | per 2000
74+ | BoolArray | set(0) | 10.37 | 0.58 |
75+ | BoolArray | set(1) | 10.25 | 0.56 |
76+ | BoolArray | get(i) | 16.03 | 0.61 |
77+ | BoolArray | setAll(0) | 96 | 17 | per 2000
78+ | BoolArray | setAll(1) | 100 | 10 | per 2000
7879| | | | |
79- | BoolArray32 | set(0) | 15.97 | |
80- | BoolArray32 | set(1) | 15.84 | |
81- | BoolArray32 | get(i) | 24.20 | |
82- | BoolArray32 | setAll(0) | 148 | | per 2000
83- | BoolArray32 | setAll(1) | 144 | | per 2000
84-
85- - UNO 16 MHz, ESP32 240 MHz.
80+ | BoolArray32 | set(0) | 15.97 | 0.56 |
81+ | BoolArray32 | set(1) | 15.84 | 0.54 |
82+ | BoolArray32 | get(i) | 24.20 | 0.59 |
83+ | BoolArray32 | setAll(0) | 148 | 12 | per 2000
84+ | BoolArray32 | setAll(1) | 144 | 8 | per 2000
85+
86+ - UNO 16 MHz (version 0.3.0)
87+ - ESP32 240 MHz (version 0.3.1)
8688- toggle() is expected to be similar to set()
87- - clear() is a wrapper around setAll(0) so similar .
89+ - clear() is a wrapper around setAll(0) so identical .
8890
8991
9092## Interface
@@ -93,19 +95,21 @@ Indicative performance figures.
9395#include " BoolArray.h"
9496```
9597
96- #### Constructor
98+ BoolArray32 is similar, uses uint32_t where BoolArray uses uint16_t.
99+
100+ ### Constructor
97101
98102- ** BoolArray()** Constructor
99103- ** ~ BoolArray()** Destructor
100- - ** uint8_t begin(uint32_t size)** dynamically allocates size elements (8 booleans in one byte).
104+ - ** uint8_t begin(uint16_t size)** dynamically allocates size elements (8 booleans in one byte).
101105Returns ** BOOLARRAY_OK** on success.
102106
103- #### Meta
107+ ### Meta
104108
105109- ** uint16_t size()** returns number of boolean elements.
106110- ** uint16_t memory()** returns number of bytes used.
107111
108- #### Base
112+ ### Base
109113
110114The following functions return ** BOOLARRAY_OK** on success.
111115
@@ -117,30 +121,38 @@ So one need to check these carefully.
117121- ** uint8_t toggle(uint16_t index)** Toggles element at index.
118122
119123
124+ ## Error codes
125+
126+ | code | value | meaning |
127+ | :----------------------:| :--------:| :----------|
128+ | BOOLARRAY_OK | 0x00 |
129+ | BOOLARRAY_ERROR | 0xFF |
130+ | BOOLARRAY_SIZE_ERROR | 0xFE | index out of range
131+ | BOOLARRAY_INIT_ERROR | 0xFD | allocation error |
132+
133+
120134## Future
121135
122136#### Must
123137
124138- improve documentation
125- - add performance figures (UNO + ESP32)
126139
127140#### Should
128141
129- - performance test on ESP32
130- - performance for ** clear()** dedicated loop vs ** setAll(0)** call
131142- investigate template class
132- - improve allocation (see PrintCharArray)
133143
134144#### Could
135145
136- - update examples.
146+ - add examples.
137147- investigate ** uint32_t array[ N] ** for BoolArray32 (ESP32?)
138148 - adjust math
139149
140150#### Wont
141151
142152- performance intern 16 bit instead of 8 bit is NOT faster on UNO
143-
153+ - strip tests in the functions for performance.
154+ - performance for ** clear()** dedicated loop vs ** setAll(0)** call
155+ - not faster.
144156
145157## Support
146158
0 commit comments