You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I agree that std::vector is overkill, and you've correctly identified the issues with it. I used std::vector in place of std::array because it's better know, but I wholly agree with you that we should change to the fixed size of std::array.
The two main reasons for moving away from uint8_t* and a byte count are to remove issues with pointing to the wrong place and to remove having to set the size of the array manually. Buffer overruns will definitely occur if the programmer has to pass the size of the array along with a pointer to it.
I will change std::vector to std::array, and we can work on implementing that in Arduino.
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.
The text was updated successfully, but these errors were encountered: