Re: in-memory files?
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