Note that there are some explanatory texts on larger screens.

plurals
  1. POState of "memset" functionality in C++ with modern compilers
    primarykey
    data
    text
    <h2>Context:</h2> <p>A while ago, I stumbled upon this 2001 DDJ article by Alexandrescu: <a href="http://www.ddj.com/cpp/184403799" rel="noreferrer">http://www.ddj.com/cpp/184403799</a></p> <p>It's about comparing various ways to initialized a buffer to some value. Like what "memset" does for single-byte values. He compared various implementations (memcpy, explicit "for" loop, duff's device) and did not really find the best candidate across all dataset sizes and all compilers.</p> <p>Quote:</p> <blockquote> <p>There is a very deep, and sad, realization underlying all this. We are in 2001, the year of the Spatial Odyssey. (...) Just step out of the box and look at us — after 50 years, we're still not terribly good at filling and copying memory.</p> </blockquote> <h2>Question:</h2> <ol> <li>does anyone have more recent information about this problem ? Do recent GCC and Visual C++ implementations perform significantly better than 7 years ago ? <li>I'm writing code that has a lifetime of 5+ (probably 10+) years and that will process arrays' sizes from a few bytes to hundred of megabytes. I can't assume that my choices now will still be optimal in 5 years. What should I do: <ul> <li>a) use the system's memset (or equivalent) and forget about optimal performance or assume the runtime and compiler will handle this for me. <li>b) benchmark once and for all on various array sizes and compilers and switch at runtime between several routines. <li>c) run the benchmark at program initialization and switch at runtime based on accurate (?) data. </ul> </ol> <p>Edit: I'm working on image processing software. My array items are PODs and every millisecond counts !</p> <p>Edit 2: Thanks for the first answers, here are some additional informations:<ul><li>Buffer initialization may represent 20%-40% of total runtime of some algorithms. <li>The platform may vary in the next 5+ years, although it will stay in the "fastest CPU money can buy from DELL" category. Compilers will be some form of GCC and Visual C++. No embedded stuff or exotic architectures on the radar<li>I'd like to hear from people who had to update their software when MMX and SSE appeared, since I'll have to do the same when "SSE2015" becomes available... :) </ul></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload