httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Havard" <bri...@kheldar.apana.org.au>
Subject Re: shmem on win32 (was RE: cvs commit: apache-2.0/src/modules/standard mod_auth_digest.c)
Date Fri, 02 Jun 2000 11:54:22 GMT
On Fri, 2 Jun 2000 20:39:44 +1000, Tim Costello wrote:

>On Friday, 02 June 2000, William A. Rowe, Jr. wrote:
>> But I'm getting past myself, and have been trying to avoid
>> the two ongoing streams of consiousness.  I'm simply trying to
>> implement shmem on Win32, not that we need it or want it :-)
>
>Cool... how? I recall reading somewhere that the only way to do it
>properly on win32 was by using memory mapped files. Anyone know a
>better way? 

It's weird but can be done. You create a file mapping using
INVALID_HANDLE_VALUE so it doesn't map to an actual file. Here's part of a
named shared memory class I wrote:

#ifdef __NT__
SharedMemory::SharedMemory( char *name, int reqsize )
: lock( name )
{
  size = reqsize;
  sharedMem = NULL;
  Creator = false;
  
  hMapping = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
0, size, Estring("SHM_") + name );

  if ( hMapping != NULL ) {
    Creator = GetLastError() != ERROR_ALREADY_EXISTS;
    sharedMem = MapViewOfFile( hMapping, FILE_MAP_WRITE, 0, 0, 0 );
  }
}


SharedMemory::~SharedMemory()
{
  if ( hMapping != INVALID_HANDLE_VALUE ) {
    UnmapViewOfFile( hMapping );
    CloseHandle( hMapping );
  }
}
#endif

-- 
 ______________________________________________________________________________
 |  Brian Havard                 |  "He is not the messiah!                   |
 |  brianh@kheldar.apana.org.au  |  He's a very naughty boy!" - Life of Brian |
 ------------------------------------------------------------------------------


Mime
View raw message