HVScrollView icon indicating copy to clipboard operation
HVScrollView copied to clipboard

Multiple inclusion

Open whaleygeek opened this issue 3 years ago • 3 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}},

whaleygeek avatar Jun 29 '22 09:06 whaleygeek

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?

adamstark avatar Aug 01 '22 18:08 adamstark

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.

whaleygeek avatar Aug 02 '22 07:08 whaleygeek

Yes, good point... hmm. How would I declare this so only one copy is created?

adamstark avatar Aug 02 '22 08:08 adamstark