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

Re: writing huge C-array to a file


  • Subject: Re: writing huge C-array to a file
  • From: Greg Hoover <email@hidden>
  • Date: Fri, 15 Sep 2006 12:23:29 -0700

I'm writing a large C-array to file using an NSFileHandle and am encapsulating the array in an NSData object. As I understand it, you have 2 options: (1) copy all the data in your array into an NSData object with new memory allocations (using initWithBytes) or (2) create an NSData object using initWithBytesNoCopy which doesn't have the overhead of copying the data new a new memory allocation. I'd like to avoid having to copy the data around unnecessarily, but using initWithBytesNoCopy is problematic because the new NSData object takes ownership of memory associated with the C-array, which means that it is deallocated with the NSData object. Since the NSData object is only used temporarily for file writing, the data that I'd like to keep around ends up being deallocated.

Is there a way to retain data from an NSData object such that when it is deallocated, it's data memory is not? Is there a more appropriate way to write the data to file?

Thank you.
Greg
_______________________________________________
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


  • Follow-Ups:
    • Re: writing huge C-array to a file
      • From: "R. Matthew Emerson" <email@hidden>
    • Re: writing huge C-array to a file
      • From: j o a r <email@hidden>
  • Prev by Date: Re: Prevent reordering on an NSTableView column
  • Next by Date: Re: writing huge C-array to a file
  • Previous by thread: To bind or not to bind(ings)
  • Next by thread: Re: writing huge C-array to a file
  • Index(es):
    • Date
    • Thread