Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualOhforf sake

Posted 28 July 2014 - 09:45 AM

Not sure if multithreading is an issue here, but be aware that for:
bool array[2];
the assignment
 array[0] = true;
is atomic.
 
std::vector<> on the other hand has a template specialization for bools, which merges them into integer values to safe space. Using std::vector<bool>  
std::vector<bool> vecArray;
//...
vecArray[0] = true;
becomes:
unsigned char tmp = vecArray[0];
tmp = tmp | (1 << 0);
vecArray[0] = tmp;
which is not atomic.

Edit: On the notion of merging the bools into integer types, have you considered C-style flags or, for a more array like experience, std::bitset?

#1Ohforf sake

Posted 28 July 2014 - 09:41 AM

Not sure if multithreading is an issue here, but be aware that for:
bool array[2];
the assignment
 array[0] = true;
is atomic.
 
std::vector<> on the other hand has a template specialization for bools, which merges them into integer values to safe space. Using std::vector<bool>  
std::vector<bool> vecArray;
//...
vecArray[0] = true;
becomes:
unsigned char tmp = vecArray[0];
tmp = tmp | (1 << 0);
vecArray[0] = tmp;
which is not atomic.

PARTNERS