I have a 3d vector of structs. I refer to where the struct is located in the 3d vector by the struct's i j and k. However, when making millions of these, it takes up a bunch of memory because the object stores so much data.
How can I efficiently figure out what i,j,k a particular struct object is without storing that information in the struct itself. Can I do it with some sort of memory arithmetic?
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
struct MyStruct {
size_t i;
size_t j;
size_t k;
bool some_bool;
};
vector<vector<vector<MyStruct>>> three_d_struct_v;
size_t max_i = 1000000;
size_t max_j = 10;
size_t max_k = 10;
for(size_t i = 0; i < max_i; i++) {
for(size_t j = 0; j < max_j; j++) {
for(size_t k = 0; k < max_k; k++) {
three_d_struct_v.emplace_back(MyStruct{i,j,k,false});
}
}
}
return 0;
}