🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17724

Re: Memory Mapped File

#17724
From: Early Ehlinger
Date: Tue, 04 Mar 2003 15:28
37 lines
2731 bytes
Three things:

1. I'm pretty sure you need to keep hFile and hFileMapping open, along with
unmapping the view when you're done you're done with the info:

hFile = CreateFile(...);
hFileMapping=CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL);
lpMapApp = MapViewOfFile(hFileMapping,FILE_MAP_READ,0,0,0);

/* use lpMapApp */

UnmapViewOfFile( lpMapApp ); /* must come before ... */
CloseHandle(hFileMapping); /* must come before ... */
CloseHandle(hFile); /* file is now officially closed */

2. MMIO does not guarantee that you will not swap.  What it does is take a
section of your process's virtual address space and set up the
virtual-memory system so that that section is "backed" by the file itself.
In other words, the first time you access the virtual address stored in
lpMapApp, you will cause a page fault which will have the effect of reading
at least 1 page of the file into physical memory.  You are *not* guaranteed
at this point that this physical page of RAM will not get cleared out for
another thread/process to use if necessary.  You *are* guaranteed that every
time you access the virtual address, the information from the file will be
available.  Will there be a page fault each time you access the address?  In
all probability, no.  But there is no guarantee at this point.

3. If you want to lock pages of RAM into physical memory, the API you're
looking for is VirtualLock.

--
-- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 --
- RenderFarm - Lightwave , 3dSMax , Bryce , Maya , AfterEffects -
--- www.respower.com -- 500+ GHz Starting At USD$0.50/GHz*Hour --
----------------- SuperComputing For the Masses! ----------------
"I'm so busy programming my computer to let me be lazy, I never
get any rest!" - John Kaster
Technical Details
Message-ID: <3e64c62c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e64c04a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,971de9213c29817a,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-03-04 12:06:09 PST
From: "Early Ehlinger" <early@respower.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e64c04a$1@newsgroups.borland.com>
Subject: Re: Memory Mapped File
Date: Tue, 4 Mar 2003 09:28:47 -0600
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 206.166.224.226
Message-ID: <3e64c62c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1046791724 206.166.224.226 (4 Mar 2003 07:28:44 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail