bcopy and bzero

bcopy and bzero

Post by Roger Butenu » Thu, 06 Aug 1998 04:00:00



|> I'm running lmbench on a few linux machines. lmbench measures (among other
|> things) bcopy bandwidth. There are two lines in the file bw_mem_cp.c which I
|> don't understand:
|>
|>           bzero(src, bytes);     /* for Linux */
|>           bzero(dst, bytes);     /* for Linux */
|>
|> Removing these lines yields much higher (although apparently innacurate)
|> numbers for bandwidth for large bcopys.
|>
|> Can anyone tell me why the calls to bzero are necessary?

When you don't initialize your source area, all your source area is
the same page, one page filled with zero bytes. This page fits nicely
in the first level cache. Reading from cache is faster than reading
from memory.

Roger

 
 
 

1. bzero() bcopy() alternatives

%% Regarding Re: bzero() bcopy() alternatives;


    adw> : Is there an alternative for using bzero() and bcopy()?  I am
    adw> : writing a program on this weird unix box that doesn't support
    adw> : these two functions.  I knew there's a str* function which
    adw> : will do the job but I forgot which one.  I've also checked
    adw> : the man pages just incase you all suggest me to "rtfm" :-)
    adw> : I'll really appreciate the help.  Thanks.

    adw> memset(3C)
    adw> memcpy(3C)

And don't forget bcmp() vs. memcmp().

It should be pointed out that compiler libraries which don't support
bzero() and bcopy() are *NOT* weird (at least not because of this fact
:).

memset and memcpy (and memmove) are the official ANSI/ISO Standard C
Library functions for performing these operations.  This standard was
first published in 1989, so I'm not surprised that 6 years later
libraries are dropping non-standard functions in preference to the
standard ones, where they overlap.

bcopy() and bzero() are _not_ standard, and (IMHO) you should always
write your code to use memcpy, memmove, memset, and memcmp.  Then on
weird systems which don't have those and _only_ have b*(), you can use
macros to redefine them.
--
-------------------------------------------------------------------------------

 Senior Software Engineer                                   Bay Networks, Inc.
-----------------------------------------------==<http://www.baynetworks.com/>-
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.

2. Would someone price these machines please?

3. Where is bcopy,bzero,bcmp?

4. possible deadlock in 2.4.4 sys_getdents ?

5. bzero and bcopy routines for Solaris2.3

6. BINFMT broken?

7. how to completely get rid of bcopy, bzero, bcmp?

8. 2 things (more unix admin based than OpenBSD specific)

9. Can't find bcopy & bzero under Solaris 2.3

10. bzero/bcopy on Solaris: Summary

11. bzero and bcopy

12. Solaris 2.3 - standard C library doesn't have bcopy, bzero, etc.

13. bzero and bcopy