memset()
is simply the wrong tool for the job here.
it's declared as:
void* memset( void* dest, int ch, std::size_t count );
Where ch
will be assigned to each byte of data. If you test what DBL_MAX
is, when casted to int, you can confirm why you are getting zeros:
int x = DBL_MAX;
std::cout << x << "\n"; // prints 0
You could mess with casting and std::fill
, but that would look pretty bad in my opinion, I think you are better off using a simple double-loop and let the compiler take care of optimizing it for you:
for(auto& l : array) {
for (auto& c : l) {
c = DBL_MAX;
}
}
Edit: Since you've tagged this as C++11, a general comment: unless you are interacting with APIs and interfaces that work directly on memory, you really should not be thinking in terms of "memory" when writing modern C++ code. Even when dealing with the core data types, it's almost always better to treat them as objects. If you are using any of the old mem...
interfaces, odds are you are tackling your problem from the wrong angle.