c++ - Stack overflow due to too big char array -
c++ beginner here, encountered first stack overflow error ever!
i've made program parses through 2 big files (a couple of million lines) 1 line @ time. subfunction below gets 2 ifstream objects (&referencepop , &wantedpop) , parses through them fstreams getline().
due few lines in files being really huge had increase size of charbuf arrays, program crashed stack overflow error... if make them small while loop break before reaching eof , if large = overflow...
i have different version of program using std::string , std::stringstream parsing managed parse through whole file, painfully slow however. wanted try below , compare performance...
is there way change charbuf arrays size match of getline each line? many lines few characters (char[128] should enough)... there performance hit having unnecessary large char arrays on these lines?
char charbufa[512000], charbufb[512000]; char *next_tokena = null; char *next_tokenb = null; bool nextline; int counter=0,noflines=0, intbufa, intbufb; double testvalue; while(referencepop.getline(charbufa,512000)&&wantedpop.getline(charbufb,512000)){ noflines++; nextline=true; char* charbufap = strtok_s(charbufa,"\t", &next_tokena); char* charbufbp = strtok_s(charbufb,"\t", &next_tokenb); lot more operations... }
Comments
Post a Comment