Thanks for the feedback. I know that I’m far from a good c programmer, but I’m not that bad.
From reading the book “The C++ Programming Language” by Bjarne Stourstrup (the maker of c++) I know a thing or two about the compiler.
First of, all sizeof(…) are replace at compile time. Secondly, all operators that can be calculated at compile time will be calculated at compile time. This makes the last two optimizations you suggest just working with the code harder.
I don’t know if you’ve runned this code your self already, but if you would have noticed that the limiting part is the PRU coprocessor and not actually the ARM processor itself.
With that in mind option 1 is just the flavor of code you choose.
About point 3: If you want to concatenate a integer to a string/char[] there are two options. First you can convert the into to a char[] with itoa() and then use strcat(), or you use the minimal slower spintf which is more readable
And lastly about point 2, if you want to write it to multiple files, you’ll have to close the old one and open the new one every time you go on to the next file.
This programs was for me to test the performance, and as you see from the one seconds sleeps I’ve build into it, it runs fine and a lot faster than it needs to be. Also from any of the examples included to libpruio you can expect the reader not to just copy the code 1:1 and live happily ever after. Everyone will edit it to their liking and performance needs. For me this runs fine and error handling with the file io is something you can implement your self, if you need it. This is example code and not production code…
And on a last note, you’ve made me aware of a little error in my code though, the line:
fwrite(io->Adc->Value, sizeof(uint16), 16000, oFile);
should be
fwrite(io->Adc->Value, sizeof(uint16), bsSize, oFile);
If you want to provide better sample code you’re free to go, but please don’t be that smart-ass stating facts that are only half or not at all true.
Greetings,
Nils Kohrs