• 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: Re: writing huge C-array to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: writing huge C-array to a file


  • Subject: Re: Re: writing huge C-array to a file
  • From: "Michael Ash" <email@hidden>
  • Date: Mon, 24 Jul 2006 11:39:07 -0400

On 7/23/06, PGM <email@hidden> wrote:
Thanks for your suggestions. I had already looked into the
documentation of NSFileHandle and NSFileManager, but not being familiar
with fileDescriptors, I did not see any obvious way to do standard C
fprintf writing with the help of those classes.

For the archives, I now use the following code in NSDocument's
"writeToFile:ofType:":

//create new file if it does not yet exist
if(![[NSFileManager defaultManager] fileExistsAtPath:fileName]){
     [[NSFileManager defaultManager] createFileAtPath:fileName
contents:[NSData data] attributes:nil];
}

FILE *writing;
NSFileHandle *handle = [NSFileHandle
fileHandleForUpdatingAtPath:fileName];
int descriptor = [handle fileDescriptor];
writing = fdopen(descriptor, "w");

//Now use fprintf for all the writing

fclose(writing);
[handle closeFile];

The above code is entirely overcomplicated. Nothing requires you to use Cocoa here. You can simplify it down to just:

FILE *writing = fopen( [fileName fileSystemRepresentation], "w" );
// write using fprintf
fclose( writing );

(Note that this replaces the entire code, including the NSFileManager bits.)

Mike
_______________________________________________
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: 
 >writing huge C-array to a file (From: PGM <email@hidden>)
 >Re: writing huge C-array to a file (From: Bill Bumgarner <email@hidden>)
 >Re: writing huge C-array to a file (From: Steve Bird <email@hidden>)
 >Re: writing huge C-array to a file (From: Bill Bumgarner <email@hidden>)
 >Re: writing huge C-array to a file (From: PGM <email@hidden>)

  • Prev by Date: Re: Finder-like color label menu item in Cocoa?
  • Next by Date: Re: Finder-like color label menu item in Cocoa?
  • Previous by thread: Re: writing huge C-array to a file
  • Next by thread: NSSearchField: sendsSearchStringImmediately is not PPC & i386 compatible?
  • Index(es):
    • Date
    • Thread