So I have a struct
struct float3
{
float x, y, z;
};
and I am trying to create a function to take the x,y,z values and map them to keys 0, 1, 2 for their respective dimension. I wrote the code below but it throws a bad alloc_exception. It appears like I'm running out of memory.
KdTree::float2map(std::vector<float3>& data)
{
std::vector<std::map<int, float> > m_pnts;
int cnt = 0;
for(int i = 0; i = data.size(); i++)
{
std::map<int, float> tmp;
tmp.insert(std::make_pair(0, data[i].x));
tmp.insert(std::make_pair(1, data[i].y));
tmp.insert(std::make_pair(2, data[i].z));
m_pnts.push_back(tmp);
std::cout << m_pnts.size() << std::endl;
}
}
return m_pnts;
}
I'm still fairly new to C++ so I'm sure there are many other ways to do this or to optimize this approach. The problem is I have to do this one 33,914,095 float3s and I can't think of another way to achieve this. Any help would be greatly appreciated.