🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Getting Started with Memory Mapped Files

#123
From: Mike Collins
Date: Wed, 11 Jun 2008 17:53
38 lines
2693 bytes
Hi All, hope everyone is well...

I've got a situation where I need to *publish* some information from a 
service to a secondary application.  I have a service created and it does 
some monitoring.  I have an event log that is written to disk but I also 
want to maintain a list of the last 20 items that were in the log file. 
Currently I've been storing these in a STL vector but now I need to provide 
access to this list, to another process.

Having read a bit about this, it seems that a Memory Mapped file would be 
the easiest option.  So I'm just experimenting with Mem Mapped Files and 
there's a few things that I don't quite understand.  I need my service to be 
able to read and write to the MMF but I don't want any other process to be 
able to modify it...

1) Is CreateFileMapping() used to create a MMF and to provide initial access 
to the MMF?  What I mean is, does my service create the initial MMF with 
CreateFileMapping(), and does my secondary process get access to the created 
MMF with the same API call, CreateFileMapping?

2) I'm assuming that using CreateFileMapping(INVALID_HANDLE_VALUE,...) means 
that I don't actually have to physically create a file on disk initially?

3) Can I increase or decrease the size of the MMF once I've called 
CreateFileMapping() or should I try and determine the maximum size that it 
will ever be, initially?

4) How to I secure the MMF so only my service can access it?

5) I'm looking at a code example in VC++ and the author seems to have used a 
mutex to control access whilst reading or writing - is this necessary?

Sorry about the length of questions, and pointers or suggestions would be 
gratefully received.

Many thanks,

Mike 
Technical Details
Message-ID: <48500053@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b80765c4c39946b4,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: Getting Started with Memory Mapped Files
Date: Wed, 11 Jun 2008 17:53:15 -0000
Lines: 40
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: 88.107.193.203
Message-ID: <48500053@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1213202515 88.107.193.203 (11 Jun 2008 09:41:55 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 2514