I try to use mmap on iOS devices with the following code
Struct stat; Integer position; Size_t size; Int FD; Fd = open ([datafile cStringUsingEncoding: NSUTF8StringEncoding], O_RDONLY); Fcntl (fd, F_NOCACHE); Position = fstat (FD & S); If (position & lt; 0) {// error handling} size = s.st_size; Funkfile log (@ "% @", @ "before reading"); Offset offset = 0; Char * data = (four *) mmap (faucet, size, PROT_READ, MAP_SHARED, fd, offset); Char * pch; Int lastPosInString = 0; PCH = strchr (data, '\ n'); Long line control = 0; While (pch! = NULL) {size_t lineLength = 0; Int posInString = pch - Data + 1; Line length = posInString - lastPosInString; Four * out = callok (line lang, size (four)); Memcpy (Outside, Data + Last Pose InString, Line Lang); Out [lineleth - 1] = '\ 0'; If (line quint> gt; 0) {// do something} lastPosInString = posInString; PCH = strchr (PCH + 1, '\ n'); LineCounter = lineCounter + 1; } Mappapp ((Zero *) data, size); Close (FD); This works but sometimes for no reason when I read a file about 3.5 MB, I get an EXC_BAD_ACCESS because my data pointer is with mmap 0xffffffff I'm thinking that's an error. And it seems only to be in the simulator. I get errno: 12 currently only guard Molok, guard edges, manipulation and simulator with zombies
I recommend reading the man page for the mmap (Open the terminal.app and type man mmap ) On the successful completion of return value, mmap () returns an indicator in the mapped area. Otherwise, the value of the MAP_FAILED has been returned and the error has been set to indicate an error. There is also a section that describes errno which can also be set
No comments:
Post a Comment