On Jun 9, 2010, at 12:56 PM, Pascal Harris wrote:

> I'm trying open a (very) large file (4GB) into an NSDocument.  Small files 
> open file.  The monster fails with the error: "The document "test.pst" could 
> not be opened.  The file is too large."  What gives - and how do I overcome 
> it?  What is the maximum size that I can open using NSDocument?

NSDocument has at least three different methods you can override to get the 
file contents. You’re using the simplest one, that hands you the entire 
contents of the file in an NSData. This doesn’t scale well to huge files. You 
want to override one of the alternative methods where you get handed the path 
or URL of the file — then you can read the data yourself however you want.

Just keep in mind that in a 32-bit process you only have about 3GB of available 
address space (regardless of how much physical RAM the computer has.) And that 
address space gets fragmented as other memory blocks are allocated and freed, 
so generally the largest contiguous block that can be allocated is a lot 
smaller.

If possible you should stream the file contents using an NSFileHandle or 
lower-level I/O calls like fopen/fread/fclose. If you absolutely have to read 
an entire huge file into an NSData, you’ll get much better performance if you 
memory-map it (using the NSMappedRead option.)

—Jens_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to