1

I want to create a simple representation of an environment that basically just represents if at a certain position is an object or is not.

I would thus only need a big matrix filled with 1's and 0'. It is important to work effectively on this matrix, since I am going to have random positioned get and set operations on it, but also iterate over the whole matrix.

What would be the best solution for this? My approach would be to create a vector of vectors containing bit elements. Otherwise, would there be an advantage of using a bitmap?

Natjo
  • 2,005
  • 29
  • 75
  • Possible duplicate of [Is using a vector of boolean values slower than a dynamic bitset?](http://stackoverflow.com/questions/16738579/is-using-a-vector-of-boolean-values-slower-than-a-dynamic-bitset) – Jonas Mar 28 '17 at 12:41

1 Answers1

1

Note that while std::vector<bool> may consume less memory it is also slower than std::vector<char> (depending on the use case), because of all the bitwise operations. As with any optimization questions, there is only one answer: try different solutions and profile properly.

Jonas
  • 6,915
  • 8
  • 35
  • 53
  • Apart from brute force trying different methods, do exist online ressources/books that I could consult for different approaches? – Natjo Mar 28 '17 at 12:55