In a class, I want to have a member representing a table which contains a list of binary data for each character in the ASCII table, so the number of rows in the table is fixed. All rows will have the same size, but the size is a variable given as a parameter. So I decided to use a two-dimensional bool
array.
I have read somewhere that it's better in C++ to use a 2D bool vector in this situation to save some space, so I tried it, but when I tested my program I found that it was much slower than the 2D bool array.
This is how I initialize my table in the initialization list of the class constructor:
bits(ALPHABET_SIZE,std::vector<bool>(M))
This will fill the table with zeros (as I want), and I'm manipulating the table later in the constructor just like I did with the 2D array, so there are no other differences in the 2D bool vector implementation that can make it slower.
Is this the correct way to do this? Or is there a better way?