• 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: in-memory files?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: in-memory files?


  • Subject: Re: in-memory files?
  • From: "R. Tony Goold" <email@hidden>
  • Date: Mon, 20 Aug 2001 02:20:08 -0400

Ah, I see! I misunderstood you, and read it as you wanting to treat a file as a chunk of memory rather than the other way around.

sprintf() and snprintf() are C functions you can use to print into a memory buffer, analogous to printf().

99 times out of 100, it's better to use snprintf() than sprintf() so that you can make sure garbled input doesn't stomp the rest of your program. Most of Microsoft's high profile bugs seem to be a result of using sprintf where they should have used snprintf :-)

The Cocoa way to do this is using NSMutableData:

NSMutableData* fileData = [[NSMutableData alloc] initWithContentsOfFile:@"/path/to/file"];
// Manipulate data using [fileData mutableBytes], snprintf(), etc...
if (! [fileData writeToFile:@"/path/to/file" atomically:YES])
{
// Warning
}
[fileData release];


Cheers,
Tony

On Sunday, August 19, 2001, at 03:32 , John C. Randolph wrote:

Thanks, but I don't think mmap() is quite what I'm after. AFAIK, mmap maps a disk file into a processes VM, but what I'm after is a way to treat a portion of memory as a file, without involving the filesystem.

-jcr


References: 
 >Re: in-memory files? (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Resizing an image in an NSTextView
  • Next by Date: Re: in-memory files?
  • Previous by thread: Re: in-memory files?
  • Next by thread: Re: in-memory files?
  • Index(es):
    • Date
    • Thread