Re: Re: darwin equivalent to linux readahead(2) function ?
Re: Re: darwin equivalent to linux readahead(2) function ?
- Subject: Re: Re: darwin equivalent to linux readahead(2) function ?
- From: "Cédric Luthi" <email@hidden>
- Date: Mon, 18 Dec 2006 16:01:04 +0100
On 12/18/06, Philippe Devallois <email@hidden> wrote:
fcntl(inFD,F_RDAHEAD,1);
man fcntl
Not so complicated ;)
Hope this helps,
Actually, I'm not sure how to use it :-(
I tried like that:
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char* argv[])
{
FILE* bigfile;
int fd;
struct stat sb;
char buf[4];
bigfile = fopen("bigfile", "r");
if (!bigfile)
return 1;
fd = fileno(bigfile);
if (fstat(fd, &sb)) {
fclose(bigfile);
return 1;
}
fcntl(fd, F_RDAHEAD, 1);
read(fd, buf, 4);
printf("bigfile size is %lld bytes\n", sb.st_size);
fclose(bigfile);
return 0;
}
But it seems it's not the way I want it to behave.
Here is the (timed) result of the execution:
$ time ./rdaheadtest
bigfile size is 118053508 bytes
real 0m0.055s
user 0m0.002s
sys 0m0.015s
It obviously has NOT loaded the whole 113 MB file into memory because
(1) I haven't heard my hard disk at all and (2) my PowerBook G4 is
probably not able to load 113 MB in less than 0.055 s.
I must be doing something wrong but the fcntl man is not really
verbose about F_RDAHEAD and it's usage.
That would be nice if you could tell me a bit more on how to actually use it.
Regards.
Cédric Luthi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden