I am restricted to using CoreFoundation in a particular app, and don’t have access to NSData.
I need to access data from a file using memory mapping because the file could be quite large. With NSData, I can achieve this using the +dataWithContentsOfURL:options:error: method, passing in the NSDataReadingMappedAlways option.
Is it possible to do this with CFData? The only function I can find to actually create a CFData object directly from a file is the CFURLCreateDataAndPropertiesFromResource() function, which does not have any option to set the memory mapping flag.
Is there a lower-level way to load a CFData object from a file using memory-mapped reads? Do I have to drop down to mmap or something?
You can create a
CFData()from a byte buffer and a count. Given this, you should just be able tommap()the file in question, and then pass the mapped byte buffer over toCFDataCreateWithBytesNoCopy(). The only real complication is you’ll need to use aCFAllocatorRefthat knows how tomunmap()as thebytesDeallocator.