November 1999
Intermediate to advanced
336 pages
6h 29m
English
One programming habit you may encounter in practice is to zero out large data structures automatically. You can do that by calling calloc() to allocate a zero-filled memory block, or you can do it yourself by invoking memset(void *block, 0, int blockLen).
In the Web server we used a buffered socket object to store incoming requests:
class BufferedStreamSocket {
private:
int sockfd; // Socket descriptor
char inputBuffer[4096];
...
};
The BufferedStreamSocket constructor automatically zeros out the input buffer:
BufferedStreamSocket::BufferedStreamSocket(...)
{
memset(buffer,0,4096);
...
}
We are not generally opposed to the memset() call. It has its place. We are opposed to it only when it achieves nothing.
A close inspection ...
Read now
Unlock full access