Cautionary tale of open, append, close - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Cautionary tale of open, append, close (/showthread.php?tid=3378) |
Cautionary tale of open, append, close - doppler - 01-14-2025 This is a cautionary tale. Machine #1, i7 8 core ddr3. Machine #2, i9 24 core ddr5 Ram drive on each machine for outputs. Only for reference here. I had a very large list of unsorted data (file #1). Each line was meant to go into another file based on a name that was inside the first file. (line by line new names) First thought would be to find the name, open destination file with append, write the line out. Then close the output file. Well this way was very slow on machine #1, somewhat slow on machine number 2. The right way to do this and 10,000% faster. Keep a running list of open file handles in a dim o$(filename,open handle#) Search the array for previous open filename. If found good keep the number in a value If not found, use next position in array for new filename and open handle #. And open new filename with append. Save in array. Write the data to appropriate filename needed. DO NOT CLOSE THE FILE. Since this is a do/loop loop and get next name from file #1. On eof(1) you are done. System or end will close all handles. Lot's of little bits in my description are needed. The core of the procedure is valid. Seems opening and closing files when using append. Is very wasteful for the processor cycles. Even in a ram drive. (my first wrong assumption) Take it for what it is. |