Hacker News new | ask | show | jobs
by saagarjha 2684 days ago
Instead of doing a memset, I'd recommend using std::fill (which will likely call memset or another fast implementation behind the scenes): it makes it clear what you are doing, and preempts questions of "is this legal to do" (which it is, but only for POD data types).
1 comments

I'm far more inclined toward

  img.assign(w*h, color);
myself.
Normally I choose the methods in <algorithm> because they take an ExecutionPolicy parameter, allowing me to make this code parallel if I wish, but both are valid.