"Nobody will ever echo this much data!"
#define BUF_INITIAL 1024
char buf[BUF_INITIAL];
int main(int argc, char** argv)
{
char* p;
...
p = len > BUF_INITIAL ? malloc(len) : buf;
...
write(1, p, len);
...
}4 KB * (many) could be frightening.
I'm also guessing that 4k was chosen because a malloc() of 1 page is faster than a malloc() of >1 page. Of course that's with the assumption that the systems use a 4k page size.