Re: preventing bad memory access

2011-10-20 Thread Don Quixote de la Mancha
On Tue, Oct 18, 2011 at 9:22 AM, Jens Alfke j...@mooseyard.com wrote: On Oct 17, 2011, at 9:26 PM, Wilker wrote: if the user is acessing a file from an external drive, and the file has 8gb, I only wanna read 64kb, so, I don't wanna read it all just for 64kb. Just use

Re: preventing bad memory access

2011-10-20 Thread Wilker
Thanks for the answers guys. I mean I will use the f* operations. But they are really safe? There is anything that I can do for extreme situations in case to avoid bad memory access? --- Wilker Lúcio http://about.me/wilkerlucio/bio Kajabi Consultant +55 81 82556600 On Thu, Oct 20, 2011 at

Re: preventing bad memory access

2011-10-20 Thread Don Quixote de la Mancha
On Thu, Oct 20, 2011 at 8:19 PM, Wilker wilkerlu...@gmail.com wrote: But they are really safe? There is anything that I can do for extreme situations in case to avoid bad memory access? Yes they are safe. The f I/O calls go back to the very beginnings of the C standard library in the late

Re: preventing bad memory access

2011-10-20 Thread Don Quixote de la Mancha
On Thu, Oct 20, 2011 at 8:48 PM, Jens Alfke j...@mooseyard.com wrote: What’s unsafe is accessing file-mapped memory after the file becomes unavailable. If you use fread (or read), you’re not doing that. You're allocating your own memory from the heap first, then copying data from the file

Re: preventing bad memory access

2011-10-20 Thread Kyle Sluder
On Oct 20, 2011, at 8:56 PM, Don Quixote de la Mancha quix...@dulcineatech.com wrote: For C++, you would need to throw an exception on I/O error, then write exception-safe code. I have not yet really figured out the right way to do the equivalent for Objective-C, because Objective-C

Re: preventing bad memory access

2011-10-18 Thread Scott Ribe
On Oct 17, 2011, at 10:26 PM, Wilker wrote: NSData *fileData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedAlways | NSDataReadingUncached error:error]; Do you retain fileData? -- Scott Ribe scott_r...@elevated-dev.com http://www.elevated-dev.com/ (303) 722-0567 voice

Re: preventing bad memory access

2011-10-18 Thread Jens Alfke
On Oct 17, 2011, at 9:26 PM, Wilker wrote: I wanna it mapped always and uncached because I don't wanna read the entire file, just some pieces of it (small pieces), so, if the user is acessing a file from an external drive, and the file has 8gb, I only wanna read 64kb, so, I don't wanna read

Re: preventing bad memory access

2011-10-17 Thread Kyle Sluder
On Mon, Oct 17, 2011 at 9:26 PM, Wilker wilkerlu...@gmail.com wrote: Hi guys, Im having a little problem here with reading NSData from a file, this is the line that starts the reading:    NSData *fileData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedAlways |