> Recently, I found out to use mmap for handling file easily.
> It just use address instead of management of buffer. Right?
> 1. But, how about the speed?
> Is it faster than normal using file descripter?
That will depend a lot on how you use the file descriptor. Mmap can sometimes
eliminate extra copies that a read() will do, especially if you're doing
small or non-aligned read, as it allows you to directly read out of the
buffercache. But there will also be some overhead associated with paging in
memory, which might be more than well-optimized read() calls.
In general, mmap is a lot more convenient than using read when you'll be
doing a lot of random access, as you don't have to do any buffer management
yourself. On the other hand, handling I/O errors with mmaped memory is much
Quote:> 2. Is it using temporary file? Is it relative with swp file in Linux?
An anonymous mapping will use the swap file. A mapping of an existing file
will use that file, at least if it's local. I'm not sure where paged-out
data goes when you're mmap-ing a file over a network.
B-Lex Information Technologies, http://www.b-lex.com/