代码之家  ›  专栏  ›  技术社区  ›  T.T.T.

较小的管道如何加速数据流?

  •  1
  • T.T.T.  · 技术社区  · 16 年前

    if (0 == CreatePipe(&hRead,&hWrite,0,1024*1024))
    {
    printf("CreatePipe failed\n");
    return success;
    }
    

    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分钟(原尺寸)

    10000=1分33秒

    怎么会这样?

    1 回复  |  直到 16 年前
        1
  •  4
  •   S.Lott    16 年前

    少等了。

    如果管道缓冲区太大,那么一个进程写入所有数据并在第二个进程开始之前关闭它的管道末端。