Re: preventing bad memory access
Re: preventing bad memory access
- Subject: Re: preventing bad memory access
- From: Don Quixote de la Mancha <email@hidden>
- Date: Thu, 20 Oct 2011 00:09:08 -0700
On Tue, Oct 18, 2011 at 9:22 AM, Jens Alfke <email@hidden> 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 fopen/fseek/fread/fclose. Mapping in the entire file just so you can read 64kb is overkill.
Specifically, if you fseek to the beginning of where you want to read,
then fread what you want, the only part that will get cached is what
you read. It will be faster than not caching.
mapping the file then reading from memory also caches parts of the
file, but only what you read.
If you're going to read your file in large chunks then it will be
faster to use the open(), lseek(), read() and close() system calls.
The "f" calls from stdio use an in-process cache which is faster for
small accesses but slower for large ones.
--
Don Quixote de la Mancha
Dulcinea Technologies Corporation
Software of Elegance and Beauty
http://www.dulcineatech.com
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden