svn commit: r253636 - head/sys/vm

David Chisnall theraven at FreeBSD.org
Thu Jul 25 11:44:07 UTC 2013


On 25 Jul 2013, at 09:11, Hans Petter Selasky <hps at bitfrost.no> wrote:

> The structure looks like some size, so bzero() might run faster than memset() depending on the compiler settings. Should be profiled before changed!

They will generate identical code for small structures with known sizes.  Both clang and gcc have a simplify libcalls pass that recognises both functions and will elide the call in preference to a small set of inline stores.

However(), memset is to be preferred in this idiom because the compiler provides better diagnostics in the case of error:

bzero.c:9:22: warning: 'memset' call operates on objects of type 'struct foo'
      while the size is based on a different type 'struct foo *'
      [-Wsizeof-pointer-memaccess]
        memset(f, 0, sizeof(f));
               ~            ^
bzero.c:9:22: note: did you mean to dereference the argument to 'sizeof' (and
      multiply it by the number of elements)?
        memset(f, 0, sizeof(f));
                            ^

The same line with bzero(f, sizeof(f)) generates no error.

David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 881 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20130725/476175e6/attachment.sig>


More information about the svn-src-all mailing list