• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask and copying lots of small files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask and copying lots of small files


  • Subject: Re: NSTask and copying lots of small files
  • From: Jonathan Fewtrell <email@hidden>
  • Date: Sat, 28 Jan 2006 19:28:10 +0000


On 28 Jan 2006, at 19:17, John Stiles wrote:



Jonathan Fewtrell wrote:
My app copies a directory from CD to the hard drive. The directory contains a few hundred small files (say 10k each).

If I use NSFileManager's copyPath method, the process is very slow. Several minutes to copy a directory that in total is only about 3MB. It is also rather nerve-wracking in that it makes the CD drive chatter throughout the process, presumably because it is seeking and copying one small file at a time. If I copy the directory in the Finder, the same thing happens.

However, if I use ditto from the Terminal, it all happens very smoothly in about 20 seconds with no chattering. So I tried using ditto via an NSTask:

- (BOOL)dittoFromPath:(NSString *)source toPath:(NSString *)target
{
NSTask *copyTask;
NSArray *arguments;
int outcome;
arguments = [NSArray arrayWithObjects:source, target, nil];
copyTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/ ditto" arguments:arguments];
[copyTask waitUntilExit];
outcome = [copyTask terminationStatus];
return outcome == 0? YES : NO;
}


But this gives the same slowness and chattering as using NSFileManager.

If ditto is a separate process why shouldn't it run as efficiently when invoked from NSTask as it does when invoked from Terminal? Any other way I can get a smooth copying process?
It's likely that the smooth, non-chattering copy was coming out of an in-memory cache, and not being read off of disc at all.
I've found that when testing CD-based operations, the disk cache can often give you misleading results. It's not 100% predictable when the cache will be used or not (it depends on how much memory you're using on your system for other things)
If you want to clear out the cache, eject and re-insert the CD immediately before doing any timing tests.



I wondered about that too, but I always get a smooth result from the Terminal, even when a CD is newly inserted (subsequent invocations run much quicker, presumably because they use the cache).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >NSTask and copying lots of small files (From: Jonathan Fewtrell <email@hidden>)
 >Re: NSTask and copying lots of small files (From: John Stiles <email@hidden>)

  • Prev by Date: IMService not defined
  • Next by Date: newb question on documents, nibs & the menu bar
  • Previous by thread: Re: NSTask and copying lots of small files
  • Next by thread: Re: NSTask and copying lots of small files
  • Index(es):
    • Date
    • Thread