Re: Creating a series of sequenced files
Re: Creating a series of sequenced files
- Subject: Re: Creating a series of sequenced files
- From: Quincey Morris <email@hidden>
- Date: Sat, 16 Apr 2016 15:12:02 -0700
- Feedback-id: 167118m:167118agrif8a:167118sQeEngraHv:SMTPCORP
On Apr 16, 2016, at 14:36 , Carl Hoefs <email@hidden> wrote:
>
> I have a daemon process that needs to generate a series of sequenced files
Oh, sorry, I think I misunderstood the question. I thought you wanted to generate all the files at once. Alex’s interpretation sounds more plausible.
If you’re looking to *resume* creating files at the end of an existing sequence, I would just do the simplest thing:
1. When your process starts, initialize a “nextInSequence” number to 0 or 1.
2. When you need to create a new file, construct its name using the “nextInSequence” variable, and increment it.
3. Try creating a new file with that name. If it fails due to conflict with an existing file, repeat step 2.
Anything “cleverer” that tries to find the last-used sequence is subject to race conditions, and multiple iterations of step 2 (to get past the files you previously created) aren’t going to take long. Still, I’d suggest you set a hard limit (e.g. 1000 attempts) on iterations, and if you hit the limit, tell the user to remove or otherwise deal with old files. The idea is that if old files are building up without limit, something needs to be done with them anyway, so you may as well be proactive about it.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden