Description
For a hybrid C/C++ (C++ wrapped in extern "C") application I'm writing I am trying to decide if it is better for me to include some static definitions my program needs to run as global variables or in an external datastore that needs to be read in every time it is run (i.e. a .csv file or sql database).
My static definitions, when laid out in a csv file, take appx 15 columns each with a maximum of 40 definitions (less than that to begin, but up to 40 due to feature scaling).
Problem
I'm torn because it feels wrong to me to include so much data as global variables that get loaded with the program at compile time. However, the overhead of reading from a datastore every time I run the program after compiling seems unnecessary.
Question
What are the best practices here? My code needs to be portable enough for someone else to understand and I do not want to obfuscate it.
It might be appropriate to generate a seperate C file from the CSV using a high level language, e.g. Python. Then either
#include
the generated file (only if used in a single module usingstatic
), or as a seperate compilation unit.That way you can easily change the values in the CSV/spreadsheet program of your choice, while still having all data available. The code generating program can be called by the build system, so no manual fiddling.