Re: functions order when do memory mapping
- From: Måns Rullgård <mru@xxxxxxxxxxxxx>
- Date: Mon, 25 Dec 2006 00:11:23 +0000
"Ronald" <followait@xxxxxxx> writes:
"Måns Rullgård" <mru@xxxxxxxxxxxxx>
??????:yw1xzm9dl1du.fsf@xxxxxxxxxxxxxxxxxxxxxxxx
Ronald <followait@xxxxxxx> writes:...
A:
open
mmap
...munmap
close
or
B:
open
mmap
close
munmap
Both works well, I wonder which is better?
It doesn't matter in general. The only time it could possibly matter
is if the file is deleted while open and/or mapped. In both cases,
the OS keeps reference counts on the inode so everything works.
If so, I think the 2nd is better.
It only makes a difference if you want the ability to change the
mapping later on, and the file may have been deleted in the meantime.
Keeping the file descriptor open allows you to make new mappings at
any time, even if all links to the inode have been deleted from the
filesystem. Keeping the file open is of course always more efficient
than reopening it each time a new mapping is needed. On the other
hand, if only a single mapping will ever be needed, closing the file
once the mapping is set up will free up a file descriptor, and
associated OS resources, which is generally a good thing. As always,
which way is best depends entirely on the circumstances.
--
Måns Rullgård
mru@xxxxxxxxxxxxx
.
- References:
- functions order when do memory mapping
- From: Ronald
- Re: functions order when do memory mapping
- From: Måns Rullgård
- Re: functions order when do memory mapping
- From: Ronald
- functions order when do memory mapping
- Prev by Date: Re: functions order when do memory mapping
- Next by Date: Re: hi frnd pls guide me regarding how to compile in linux2.10.18
- Previous by thread: Re: functions order when do memory mapping
- Next by thread: open problem
- Index(es):
Relevant Pages
|