Useless Computations

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 ...

Get Efficient C++ Performance Programming Techniques now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.