2013-07-18 27 views
0

爲什麼慢慢讀一個文件來尋找它會更好?c#尋找與讀取

//if (!read_fields[x] || !ok) 
        //{ 
        // if (l > 0) Seek(l, SeekOrigin.Current); 
        // read[x] = null; 
        // continue; 
        //} 

        byte[] bx = new byte[l]; 
        if (l > 0) Read(bx, 0, l); 

        if (!read_fields[x] || !ok) 
        { 
         read[x] = null; 
         continue; 
        } 

我的速度測試說,追求的是速度很慢!

+2

請參閱:http://stackoverflow.com/questions/4369278/filestream-seek-vs-buffered-reading –

回答

1

Seek - 將此流的當前位置設置爲給定值。 Read - 從流中讀取一個字節塊並將數據寫入給定的緩衝區。

因此,尋求你重新定位閱讀位置 - 這是一個耗時的過程。如果你簡單閱讀 - 你從文件中順序閱讀。

+0

然後比尋找更好的閱讀? –