Given a struct MyData
, of which many instances exist (I'd say several millions at most), for each instance I need to store a member which may contain values for up to 8 keys. The key will always be an int
ranged 0-7
, and the values will always be a 3D point of floats (let's call it Point3
).
At maximum, it would contain:
Key | Value
-------------
0 | [x,y,z]
1 | [x,y,z]
2 | [x,y,z]
3 | [x,y,z]
4 | [x,y,z]
5 | [x,y,z]
6 | [x,y,z]
7 | [x,y,z]
However, in 99.9% of cases it will contain 0 or 1 key-value pairs, e.g.:
Key | Value
-------------
1 | [x,y,z]
How can I efficiently determine the memory overhead, if any, of storing an empty or single-valued std::map<int, Point3>
, compared to always storing an array of 8 Point3
(4 bytes per float * 3 values * 8 slots = 96 bytes) and a single BYTE
with bits for which slots contain meaningful values?
In generality, my question is what is the memory overhead of an empty or almost empty std::map
?