Board index » delphi » Where are memory-mapped files kept?

Where are memory-mapped files kept?

Hi

It seems a silly question at first, "Where are memory-mapped files
kept?", but are they kept in RAM or do the files just become part of
virtual memory and hence a part of the swap section on disk?

I have a series of threads, each of which will be using sound files to
make announcements according to circumstances. To reduce disk thrashing
and speed up response, I want to load these files into RAM. Now,
presuming that I have enough physical-RAM installed on my machine, will
memory-mapping these files take advantage of it, or will I then have to
move the data into memory that's been specifically allocated using
GetMem?

Thanks in advance.

Graham

 

Re:Where are memory-mapped files kept?


Quote
In article <33F9366B.7...@dial.pipex.com> Graham Clemie <z...@dial.pipex.com> writes:
>It seems a silly question at first, "Where are memory-mapped files
>kept?", but are they kept in RAM or do the files just become part of
>virtual memory and hence a part of the swap section on disk?
>I have a series of threads, each of which will be using sound files to
>make announcements according to circumstances. To reduce disk thrashing
>and speed up response, I want to load these files into RAM. Now,
>presuming that I have enough physical-RAM installed on my machine, will
>memory-mapping these files take advantage of it, or will I then have to
>move the data into memory that's been specifically allocated using
>GetMem?

In the Win95/WinNT environment, designers should treat memory as being
synonymous with disk space.  

All memory is virtual.  If you have lots of RAM, then lots of that can be in
memory but any portion of it can be swapped in or out at any time for any
reason.

A 'memory mapped file' is mapped into a portion of *virtual* storage, which
simply means that it is some part of the virtual-memory swap file.

Re:Where are memory-mapped files kept?


Quote
Sundial Services wrote:
> In the Win95/WinNT environment, designers should treat memory as being

> synonymous with disk space.

> All memory is virtual.  If you have lots of RAM, then lots of that can
> be in
> memory but any portion of it can be swapped in or out at any time for
> any
> reason.

> A 'memory mapped file' is mapped into a portion of *virtual* storage,
> which
> simply means that it is some part of the virtual-memory swap file.

No!  Not all memory is virtual.  All memory can be virtualized!  That is
different.  The memory that an application currently has committed is
real.  It is not virtual until the OS decides to page swap from that
application.

A memory mapped file is a disk file that through some OS trickery has a
linear mapping (of all of or some part of it) in memory.  One of the
options is to map a portion of the virtual-memory swap file.  A much
more common usage is for loading DLL's and EXE's under NT.  In the case
of EXE's, the system simply maps a section of virtual memory to that
file, and jumps to the entry point.  The advantage that memory mapped
files have over other types of files in this situation is that the OS
can de-virtualize them as necessary.  In other words, the OS does not
need to load the entire EXE at one time.  It only loads those portions
that the processor tries to execute.  If you have a 5M .EXE but are only
using 200K of it, the savings can be substantial.

-andrew

Other Threads