Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on the quality of the compiler and the libraries. In most cases memset is superior.</p> <p>The advantage of memset is that in many platforms it is actually a <a href="http://en.wikipedia.org/wiki/Intrinsic_function" rel="nofollow noreferrer">compiler intrinsic</a>; that is, the compiler can "understand" the intention to set a large swath of memory to a certain value, and possibly generate better code. </p> <p>In particular, that could mean using specific hardware operations for setting large regions of memory, like SSE on the x86, AltiVec on the PowerPC, NEON on the ARM, and so on. This can be an enormous performance improvement. </p> <p>On the other hand, by using a for loop you are telling the compiler to do something more specific, "load this address into a register. Write a number to it. Add one to the address. Write a number to it," and so on. In theory a perfectly intelligent compiler would recognize this loop for what it is and turn it into a memset anyway; but I have never encountered a real compiler that did this.</p> <p>So, the assumption is that memset was written by smart people to be the very best and fastest possible way to set a whole region of memory, for the specific platform and hardware the compiler supports. That is <a href="https://stackoverflow.com/questions/171917/state-of-memset-functionality-in-c-with-modern-compilers">often</a>, <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31750" rel="nofollow noreferrer">but not always</a>, true.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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