Article View: borland.public.cppbuilder.nativeapi
Article #164when to call MapViewOfFile()
From: Mike Collins
Date: Sun, 29 Jun 2008 22:50
Date: Sun, 29 Jun 2008 22:50
33 lines
1951 bytes
1951 bytes
Hay guys, just a really quick question.
Post the other week about using Memory Mapped Files and Remy gave me a
really good reply.
Just to summarise, I have a service that creates a MMF. It protects access
to it using a mutex. Client applications wait for the mutex to be release
and then can read the data from the MMF. For the client, remy suggested
this order of operations:
--- application ---
hMapping = OpenFileMapping(FILE_MAP_READ, FALSE, "MyFileMapping");
hMutex = OpenMutex(SYNCHRONIZE, FALSE, "MyFileMappingMutex");
...
// for each read operation...
if( WaitForSingleObject(hMutex, 1000) == WAIT_OBJECT_0 )
{
// Perform read operation on the MMF...
ReleaseMutex(hMutex);
}
...
CloseHandle(hMutex);
CloseHandle(hMapping);
My question is, do you have to call MapViewOfFile() each time you read the
MMF or can it be called once, initially. For example, should it be called
from within the WaitForSingleObject() call? Seems to work either way, just
want to know what is the best practice.
Many thanks in advance,
Mike
Technical Details
Message-ID:
<486800e2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9e6b8470002d53ed,start X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost> Newsgroups: borland.public.cppbuilder.nativeapi Subject: when to call MapViewOfFile() Date: Sun, 29 Jun 2008 22:50:20 -0000 Lines: 35 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 NNTP-Posting-Host: 82.1.160.148 Message-ID: <486800e2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214775522 82.1.160.148 (29 Jun 2008 14:38:42 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail