So... let's say I have about 1200 exported boolean variables in global space and I'd like to put them in a struct and export the struct instead in a more thread-safe manner. Since a struct is contiguous (including padding) and I'm in a slightly memory constricted environment, I don't think it efficient to have a contiguous data type. Creating a struct of pointers instead more than doubles the amount of memory allocated.
I somewhat lack how exported variables are allocated at a lower level but is my thinking correct? I just need a contextually in-tact struct but I don't want it to be contiguous. I don't want a struct of pointers since this increases memory cost.
My next best in line is having a struct of bitfields instead of full booleans to lower memory cost... but again, this would be quite a few bitfields and I don't need them to be contiguous.
With bitfields, 1200 boolean values would only consume 150 bytes. Is your memory constricted so much that you cannot carve our 150 bytes for these values?
If that is a non-starter, I would categorize my boolean values and make separate structures for each of the categories.
You probably want to look at the bitset template class (http://www.cplusplus.com/reference/bitset/bitset/). I personally haven't had an opportunity to use the class yet, but others on this forum can give you the guidance you need.
Well, it's just a hypothetical situation.... the realistic situation has quite a few more booleans (add a few more zeros) but even then, I'm not *that* concerned with it. I just figured it might reduce memory fragmentation issues. The two best solutions to this I find are splitting memory allocations and reducing memory allocations in the first place. I can do the latter, I'm having issues coming up with implementations of the former.