Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there std::memset equivalent for std::array?

Is there a memset equivalent for std::array? I think memset is supposed to perform better when initializing an array to zero than looping over the array. I searched one for std::array but could not find anything online.

like image 531
nmd_07 Avatar asked Jun 06 '26 03:06

nmd_07


1 Answers

Use the array's fill() method, that is what its purpose is.

If you fill it with 0 (for integers, for instance), then the compiler may optimize it if it can (often does, you can look at the generated code).

like image 163
Matthieu Brucher Avatar answered Jun 08 '26 17:06

Matthieu Brucher