Multiple inclusion
whaleygeek opened this issue · 4 comments
Hi Adam,
This is a nice header-only library.
Quick Q: If the header is included in two different cpp files, won't you get two independent copies of the aiff sample rate table, because the static will be scoped to within the cpp file that included it?
// Pre-defined 10-byte representations of common sample rates
static std::unordered_map <uint32_t, std::vector<uint8_t>> aiffSampleRateTable = {
{8000, {64, 11, 250, 0, 0, 0, 0, 0, 0, 0}},
Hi David, sorry for the late reply here. I just tried this in a test project and didn't have any compilation issues. But did you mean that these two copies would be taking up extra memory unnecessarily?
Hi Adam,
Yes, memory overhead. I was inspired by your code using the 'single header file' concept and applied the same technique to one of my embedded projects, but suffered this issue with initialised tables myself, so I was wondering if you were aware of it. I must admit my use-case is a bit different as I am on a tiny platform with limited memory, where every byte counts!!
David.
Yes, good point... hmm. How would I declare this so only one copy is created?