Skip to content

std::vector might be overkill #41

Description

@Poofjunior

The bosch hardware interface has been rewritten at the top-level to accept std::vector<uint8_t> references instead of a pointer to an array and the size of that array. While this works and shortens the number of arguments, vectors are designed to be resized dynamically. Since we know exactly how many bytes we want to read from the sensor, and since that number is fixed at compile time, we can simply use a std::array to promote readability. The top-level reader of the bosch_hardware_interface header file doesn't know this, but we have to call the size() member function before reading out the number of bytes in the driver code. Switching over to two arguments: an array pointer and a uint8_t specifying how many bytes to read/write will make compiling the code for bare-metal platforms like the Arduino much easier since we wont have to find or write a basic std::vector implementation for Arduino.

To use the code that currently uses std::vectors on the Arduino will require that we find an implementation of std::vectors for Arduino. Writers of a std::vector implementation on Arduino will need to implement dynamic resizing for the implementation to be a proper port to the Arduino. Since we don't use this feature, we may be able to switch back to array pointers to be able to implement the driver both on the pc and directly on the Arduino.

Lastly, I did a quick size check for vectors vs fixed-size arrays. Two simple programs: one creates a fixed size array of uint8_ts of size 4 and the other creates a std::vector of uint8_ts of size 4. The fixed size array is 8.3kB and the std::vector is 15.4kB.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions