Reputation: 4246
I have some files that are of size 6.7GB, and more (these are video files). I want to get chunks of file data to send to my server, so what I currently do is :
contents = [fileManager contentsAtPath:path];
if (mFileOffset<[contents length]) {
NSRange range = NSMakeRange(mFileOffset, (allowedSize>[contents length]?[contents length]:allowedSize);
contents =[contents subdataWithRange:range];
However, this produces a memory issue:
malloc: *** mmap(size=616927232) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
APP(2700,0x4136000) malloc: *** mmap(size=616927232) failed (error code=12)
*** error: can't allocate region
Is there a way like fseek
in c++
so that I read bytes of the file that come in the specified range only?
Upvotes: 0
Views: 486
Reputation: 46543
There is a method in NSFileHandle which synchronously reads data up to the specified number of bytes.
-[NSFileHandle readDataOfLength:]
For seeking :
– offsetInFile
– seekToEndOfFile
– seekToFileOffset:
Upvotes: 3
Reputation: 130102
fseek
is not C++
, it's a C
function. The same function is available in Obj-C
.
Note that Obj-C
is only a layer over C
and every valid C
code is also a valid Obj-C
code.
The file functions are also abstracted into an Obj-C
class NSFileHandle
. However, this class has exactly the same functionality as fopen
, fseek
, fclose
etc.
Upvotes: 2