Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple inclusion #61

Closed
whaleygeek opened this issue Jun 29, 2022 · 4 comments
Closed

Multiple inclusion #61

whaleygeek opened this issue Jun 29, 2022 · 4 comments

Comments

@whaleygeek
Copy link

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}},
@adamstark
Copy link
Owner

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?

@whaleygeek
Copy link
Author

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.

@adamstark
Copy link
Owner

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

@adamstark
Copy link
Owner

Dropping in from the future here... I got rid of the sample rate table finally :) Those values are calculated algorithmically now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants