🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Getting Started with Memory Mapped Files

#132
From: Jason Cipriani
Date: Fri, 13 Jun 2008 19:26
58 lines
3852 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message 
news:48500053@newsgroups.borland.com...
> 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...

There are a lot of other legitimate options that can be easier to deal with 
than sharing memory mapped files.

For instance, you can use named pipes (which also let you transparently 
publish data to applications existing on other machines over a network, 
simply by including the host name in the pipe name), start here:

http://msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx

If you use a named pipe, you'd have the service create the pipe and act as a 
"pipe server", clients create pipes by name, connect, and on connect the 
server dumps the log info through the pipe. It can also keep sending updates 
through the pipe as well. No need to deal with locking access to memory 
mapped files with mutices or whatever -- processes aren't *sharing* the same 
resource so you don't have to worry about inter-process synchronization at 
all.

You can also use mailslots:

http://msdn.microsoft.com/en-us/library/aa365147.aspx

They only work if everything is on the same local machine, but they do 
provide a queue if nobody is connected, which may or may not be more 
appropriate for your situation.

You can also use sockets and send via TCP or UDP. Use the loopback network 
for communicating between processes on the same machine, and you get a 
transparent ability to send data to other machines on the network. Using 
sockets is going to be identical to using named pipes (although the pipes 
are nice since you can give them unique names and don't have to worry about 
conflicting ports or anything like that).

Yet another simple option is to just create a file in a well-known location. 
Dump the log info to the file, and interested applications can simply read 
the file. There's no shame in this, hehe.

Anyways, I suggest named pipes instead of memory mapped files. They're 
really easy to use, provide a lot of nice features, and you don't have to 
worry about inter-process synchronization either.

Jason
Technical Details
Message-ID: <4852c9fa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <48500053@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b80765c4c39946b4
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Jason Cipriani" <jason.cipriani@nospam-gmail.com>
From: "Jason Cipriani" <jason.cipriani@nospam-gmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <48500053@newsgroups.borland.com>
Subject: Re: Getting Started with Memory Mapped Files
Date: Fri, 13 Jun 2008 15:26:50 -0400
Lines: 60
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 24.189.102.41
Message-ID: <4852c9fa$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1213385210 24.189.102.41 (13 Jun 2008 12:26:50 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail