Bzero:
Prototype: void bzero (void * s, int N );
Function: set the first n Bytes of the byte string s to zero and include '\ 0 '.
Note: bzero has no return value, and strings is used. h header file, strings. h was once part of the POSIX standard, but in the POSIX.1-2001 standard, these functions are marked as legacy functions and are not recommended.
These functions are no longer in the POSIX.1-2008 standard. We recommend that you use memset instead of bzero.
Memset:
Void * memset (void * s, int CH, size_t N );
Function explanation: Replace the first n Bytes in S with CH and return S;
Memset: fills in a given value in a memory block. It is the fastest way to perform the clearing operation on a large struct or array.
Three Common Errors:
First, the location of CH and N is reversed. remember that if you want to clear a char a [20], it must be memset (A, 0, 20) instead of memset (A, 20, 0)
Second, over memset, I think these programmers may have some psychological shadows. They are afraid of uninitialized memory, so they will write such code:
Char buffer [20]; memset (buffer, 0, sizeof (char) * 20); strcpy (buffer, "123 ");
The memset here is redundant, because the memory will be overwritten immediately, and clearing is meaningless.
Third: in fact, this error cannot be regarded as a memset error, but it often appears when memset is used;
Conclusion: for the initialization of character arrays, bzero and memset have no significant difference in efficiency. However, in the stress test of the project, the performance is obviously decreased, it becomes suspicious to initialize several temporary character arrays in the Program (using bzero. Therefore, the initialization method with the first character set to zero instead of all set to zero is modified, and the response is significantly improved. Originally, bzero is required to initialize the temporary array for each result retrieved by MP3. Each request requires 30 bzero to set zero for the temporary array. As a result, if it is not necessary, only the initialization method of the first (or first few) character of the temporary array is compared and bzero is used, the performance can be significantly improved.