0

Currently, I'm serially creating/writing data to ~30,000 files using this code:

    if ([[NSFileManager defaultManager] fileExistsAtPath:[_output_url path]]) {
        //file already exists, append string to it
        NSFileHandle *aFileHandle = [NSFileHandle fileHandleForWritingAtPath:[_output_url path]];
        [aFileHandle seekToEndOfFile];
        [aFileHandle writeData:[dataString dataUsingEncoding:NSUTF8StringEncoding]];
    } else {
        //create file
        [dataString writeToFile:[_output_url path] atomically:YES encoding: NSUTF8StringEncoding error: NULL];
    }

As you can guess, it takes quite a bit of time for this to run through 30k files. However, I'm wondering if there is a way to make this more efficient. I've looked at NSOutputStream - would this be a viable alternative? Or am I always limited by the speed at which the system can write the data to a file?

objectiveccoder001
  • 2,981
  • 10
  • 48
  • 72
  • how often will you come back to a file after writing to it? almost never or almost always, or only after the application or routine is run again? – Michael Dautermann Sep 27 '13 at 01:58
  • Almost always. I first write a little bit of data to all 30k files (initial file creation) -- then I write small bits of data to each file many times. Sometimes 5000 times. – objectiveccoder001 Sep 27 '13 at 03:29

0 Answers0