cURL / Mailing Lists / curl-library / Single Mail


Re: FILE * => fd ?

From: Andrew Francis <>
Date: Mon, 13 Aug 2001 10:38:35 +0800

> But I could imagine it being signifigantly slower on larger files,
> as how many function calls do you think it is (which then
> into system calls) to read data from a 3gig file?

I don't think the system calls are quite as bad as they seem - all the
mmap does is map addresses in virtual memory to data on the disk. When
you actually try to read from an address, every so often the data isn't
actually going to be loaded into memory - so you get a page fault,
control passes to the kernel (hence you have a context switch - the main
overhead involved in a system call) and it loads the data from the disk.

The mmap has the advantage that you don't have to worry about how much
you want to load at a time, so you may end up with *less* context
switches - but you certainly don't get rid of them completely.

And to be pedantic, you're going to have trouble mmaping a 3gb file into
the 4gb address space of most of the machines out there, especially
since lots of OSes tend to just grab a quarter of it for themselves :)
You could get clever and mmap it a gig at a time though...

Andrew Francis
Curl-library mailing list
Received on 2001-08-13