【发布时间】:2010-08-10 02:21:35
【问题描述】:
有一个 1MB 的管道:
if (0 == CreatePipe(&hRead,&hWrite,0,1024*1024))
{
printf("CreatePipe failed\n");
return success;
}
一次发送 4000 个字节 (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.
当我把管道做得更小时,发送和读取的总时间变小了很多。
将管道尺寸更改为 –
1024*1024 = 2 分钟(原始大小)
1024*512 = 1 分 47 秒
10,000 = 1 分 33 秒
任何低于 10k,1 分 33 秒
这怎么可能?
【问题讨论】:
-
呸,
if (0 == ...)? :P 至少让它if (... == 0)让它读起来像普通语言。但是从整数类型到布尔类型的隐式转换无论如何都是b ? 1 : 0,所以根本不需要。
标签: c++ windows multithreading winapi pipe