Why (ftruncate+mmap+memcpy) is faster than (write)?
问题 I found a different way to write data, which is faster than normal unix write function. Firstly, ftruncate the file to the length we need, then mmap this block of file, finally, using memcpy to flush the file content. I will give the example code below. As I known, mmap can load the file into the process address space, accelerating by ignoring the page cache. BUT, I don't have any idea why it can fast up the writing speed. Whether I write a wrong test case or it can be a kind of opti trick?