Have a 1MB pipe:
if (0 == CreatePipe(&hRead,&hWrite,0,1024*1024))
{
printf("CreatePipe failed\n");
return success;
}
Sending 4000 bytes at a time (bytesReq = 4000)
while ((bytesReq = (FileSize - offset)) != 0)
{
//Send data to Decoder.cpp thread, converting to human readable CSV
if ( (0 == WriteFile(hWrite,
readBuff,
bytesReq,
&bytesWritten,
0) ) ||
(bytesWritten != bytesReq) )
{
printf("WriteFile failed error = %d\n",GetLastError());
break;
}
}
Only 4 bytes at a time being read in at another thread, on other end of pipe.
When I made the pipe smaller, the total time of sending and reading got a lot smaller.
Changed the Pipe Size to –
1024*1024 = 2 minutes (original size)
1024*512 = 1min 47 sec
10,000 = 1min 33 sec
Anything below 10k, 1min 33 sec
How can this be?
Less waiting.
If the pipe buffer is too big, then one process writes all the data and closes it’s end of the pipe before the second process even begins.
When the pipe is too big, the processes are executed serially.