Home

filemapping

File mapping, commonly called memory-mapped file, is a mechanism that maps a file or a portion of a file into a process’s address space. Once mapped, the file contents can be accessed through ordinary memory reads and writes as if they resided in RAM. The operating system handles paging data in and out of disk, and changes may be propagated back to the file depending on the mapping mode and permissions.

Implementation varies by platform. In Windows, the process uses APIs such as CreateFileMapping and MapViewOfFile to

Benefits include reduced data copying since I/O can occur via the page cache, simplified access to large

Common considerations or limitations include platform-specific behavior, synchronization requirements for shared mappings, and potential page faults

create
a
mapping
object
and
a
view
into
the
file.
In
POSIX
systems,
mmap
creates
the
mapping
and
munmap
releases
it.
Mappings
can
be
read-only,
read-write,
or
executable,
and
can
be
shared
between
processes
or
private
to
one
process.
When
multiple
processes
map
the
same
file
with
a
shared
mapping,
changes
are
visible
to
all
mappings.
or
random-access
data,
and
the
ability
to
share
data
between
processes
through
a
common
mapped
region.
This
technique
is
often
advantageous
for
large
datasets
and
for
zero-copy
I/O
patterns,
where
computation
overlaps
with
data
loading.
that
can
cause
latency
spikes.
Large
mappings
consume
virtual
address
space
and
may
behave
differently
when
the
underlying
file
changes
size.
Proper
use
requires
attention
to
access
modes,
synchronization,
and
lifecycle
of
the
mapped
region
to
avoid
inconsistencies.