void *memset(void *dest, int c, size_t count)
The 3rd argument is the Number of characters or bytes in the array. How would you memset an array of bool
memset sets memory in multiples of bytes. So, the only way is to add padding to your bool pointer such that its length is a multiple of 8. Then do memset. Personally I would prefer if there were any other alternative than putting a redundant padding. But I haven't found any alternative solution to date.
Simply like this example:
bool primes[MAX]; memset(primes,true,sizeof(primes));
memset(buffer_start, value, sizeof(bool) * number_of_bools);
To set array of 11 bool elements to e.g. true by using
const int N = 11; bool arr[N]; memset(arr, 1, sizeof(bool) * N);
//Array declaration bool arr; //To initialize all the elements to true memset(arr,1,sizeof(arr));
Similarly, you can initialize all the elements to false, by replacing 1 with 0.
std::fill() should use
memset() when possible.
std::fill(std::begin(bArray), std::end(bArray), value);