Re: How to share object between processes?

christophepichaud_at_hotmail.com
Date: 11/02/04


Date: Tue, 2 Nov 2004 18:51:14 +0100

Sharing objects between processes can be handled using named kernel object.
J.Richter described it in some Ms Press Books.

You can also check MSDN library with queries like "MapViewOfFile" or
"MapViewOfFile CreateFileMapping"

Check also articles like
- "Visual C++ 6.0 Technical Articles-Developing Optimized Code with
Microsoft Visual C++ 6.0"
- "Memory Technical Articles - Managing Memory-Mapped Files in Win32"

Look also at Platform SDK - Storage
Look at the overview sections:

<<
Sharing Files and Memory

File mapping can be used to share a file or memory between two or more
processes. To share a file or memory, all of the processes must use the name
or the handle of the same file mapping object.

To share a file, the first process creates or opens a file by using the
CreateFile function. Next, it creates a file mapping object by using the
CreateFileMapping function, specifying the file handle and a name for the
file mapping object. The names of event, semaphore, mutex, waitable timer,
job, and file mapping objects share the same name space. Therefore, the
CreateFileMapping and OpenFileMapping functions fail if they specify a name
that is in use by an object of another type.

To share memory that is not associated with a file, a process must use the
CreateFileMapping function and specify INVALID_HANDLE_VALUE as the hFile
parameter instead of an existing file handle. The corresponding file mapping
object accesses memory backed by the system paging file. You must specify a
size greater than zero when you specify an hFile of INVALID_HANDLE_VALUE in
a call to CreateFileMapping.

The easiest way for other processes to obtain a handle of the file mapping
object created by the first process is to use the OpenFileMapping function
and specify the object's name. This is referred to as named shared memory.
If the file mapping object does not have a name, the process must obtain a
handle to it through inheritance or duplication. For more information on
inheritance and duplication, see Inheritance.

Processes that share files or memory must create file views by using the
MapViewOfFile or MapViewOfFileEx function. They must coordinate their access
using semaphores, mutexes, events, or some other mutual exclusion technique.
For more information, see Synchronization.

A shared file mapping object will not be destroyed until all processes that
use it close their handles to it by using the CloseHandle function.

For information about file mapping object security, see File Mapping
Security and Access Rights.

>>

Regards,
    Christophe Pichaud
    CPi21 LLC
    http://www.pichaud.com

"Jonghyun. Yoon (À±Á¾Çö)" <lucifer@nownuri.net> wrote in message
news:e7vtgoPwEHA.3416@TK2MSFTNGP09.phx.gbl...
> Hi.
>
> I want to share object between processes using memory map files.
> This object have several other object. (CMap, CList, CString, etc.)
> Thus, size of that class is dynamic.
>
> How can I share object between processes? plz. ¤Ð.¤Ð
>
>



Relevant Pages

  • Re: Memory mapped file pages getting cleared when memory overcommi
    ... File mapping object keeps a reference to the FILE_OBJECT, ... I have a win32 program running on XP Pro that is using a memory mapped ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Lisp Garbage Collection
    ... have not been fully ported to Windows. ... difficult to port most Lisp implementations because of difference ... address for the memory block. ... so you would use the file mapping functions. ...
    (comp.lang.lisp)
  • Re: Memory Mapped File Problem
    ... You appear to have created a file mapping that is one granual long, ... > I want to read a portion of a large file into a memory mapped ... Since I don't need the full file in the memory, ... > flProtect, 0, dwLength, sMappingName); ...
    (microsoft.public.vc.mfc)
  • Re: Memory Mapped File Problem
    ... You appear to have created a file mapping that is one granual long, ... > I want to read a portion of a large file into a memory mapped ... Since I don't need the full file in the memory, ... > flProtect, 0, dwLength, sMappingName); ...
    (microsoft.public.vc.language)
  • Re: Trying to use MemoryMappings but having a simple problem...
    ... interested process can simply open the file mapping by name. ... > MapViewOfFile()) have the same address? ... The other process can then add that offset to the address ... to share memory, but not address space. ...
    (comp.lang.pascal.delphi.misc)

Loading