Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: memory device context coordinates Pin
Alexander Kindel6-Feb-19 13:44
Alexander Kindel6-Feb-19 13:44 
AnswerRe: memory device context coordinates Pin
leon de boer6-Feb-19 15:55
leon de boer6-Feb-19 15:55 
GeneralRe: memory device context coordinates Pin
Alexander Kindel7-Feb-19 23:23
Alexander Kindel7-Feb-19 23:23 
GeneralRe: memory device context coordinates Pin
leon de boer8-Feb-19 21:43
leon de boer8-Feb-19 21:43 
AnswerRe: memory device context coordinates Pin
Alexander Kindel8-Feb-19 9:22
Alexander Kindel8-Feb-19 9:22 
QuestionMenu bar on title bar of application Pin
jung-kreidler6-Feb-19 2:23
jung-kreidler6-Feb-19 2:23 
QuestionChanged CMDIChildWnd to CMDIChildWndEx: does not show anything inside the frame Pin
Dansveen4-Feb-19 2:02
Dansveen4-Feb-19 2:02 
Question_findfirst and fopen very slow Pin
cristiapi31-Jan-19 1:13
cristiapi31-Jan-19 1:13 
I have about 1800 text files in a dir and their number is slowly growing (several files in a day). The size of a file is about 40 kB.
I need to enumerate all the file with the ".states" extension, open the file, check to see if there is a line that starts with a particular sequence of 4 chars and if the line exists, I save the line in a std::vector.

I use the following code, but it takes very long time at the first run (the subsequent runs are very fast):
C++
struct _finddata_t fd; long hFile;
if((hFile=_findfirst("*.states", &fd))== -1L) return; // File not found
do {
    FILE *f= fopen(fd.name, "rS");
    while(fgets(buf, sizeof(buf), f)) {
        if(0 == _strnicmp(buf, "ABCD", 4)) {
            Save buf in a std::vector
            break;
        }
    }
    fclose(f);
} while(_findnext(hFile, &fd) == 0);
_findclose(hFile);

Is there any way to speedup the code?

If I merge all the files in a single file, I solve the problem, but I prefer to keep all the original files.
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 3:50
David Crow31-Jan-19 3:50 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 3:58
cristiapi31-Jan-19 3:58 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 4:23
David Crow31-Jan-19 4:23 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 5:34
cristiapi31-Jan-19 5:34 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:01
David Crow31-Jan-19 6:01 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 6:07
cristiapi31-Jan-19 6:07 
GeneralRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:14
David Crow31-Jan-19 6:14 
QuestionRe: _findfirst and fopen very slow Pin
jeron131-Jan-19 4:58
jeron131-Jan-19 4:58 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 5:20
cristiapi31-Jan-19 5:20 
QuestionRe: _findfirst and fopen very slow Pin
David Crow31-Jan-19 6:04
David Crow31-Jan-19 6:04 
AnswerRe: _findfirst and fopen very slow Pin
cristiapi31-Jan-19 6:10
cristiapi31-Jan-19 6:10 
GeneralRe: _findfirst and fopen very slow Pin
jeron131-Jan-19 8:28
jeron131-Jan-19 8:28 
GeneralRe: _findfirst and fopen very slow Pin
cristiapi1-Feb-19 5:57
cristiapi1-Feb-19 5:57 
AnswerRe: _findfirst and fopen very slow Pin
Randor 31-Jan-19 14:23
professional Randor 31-Jan-19 14:23 
GeneralRe: _findfirst and fopen very slow Pin
cristiapi1-Feb-19 0:29
cristiapi1-Feb-19 0:29 
AnswerRe: _findfirst and fopen very slow Pin
leon de boer31-Jan-19 14:54
leon de boer31-Jan-19 14:54 
GeneralRe: _findfirst and fopen very slow Pin
Stefan_Lang31-Jan-19 21:36
Stefan_Lang31-Jan-19 21:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.