CreateFileMapping Question

From: Bruce Kingsley (brucek5_at_mindspring.com)
Date: 05/21/04


Date: Fri, 21 May 2004 02:38:29 GMT

All:

I have a question about the use of CreateFileMapping functions. See example
below...

First Process:

 HANDLE hmem = ::CreateFileMapping((HANDLE) 0xFFFFFFFF, NULL,
PAGE_READWRITE, 0, FileSize, FM_SCOPEMAPFILENAME);

 FileBuffer = (SampleTransferType*)::MapViewOfFile(hmem, FILE_MAP_WRITE, 0,
0, FileSize);

// Fill FileBuffer here....

 ::UnmapViewOfFile(FileBuffer);
 ::CloseHandle(hmem);

Second Process:

 HANDLE hmem = ::OpenFileMapping(FILE_MAP_WRITE, FALSE, FM_ADCMAPFILENAME);

 FileBuffer = (SampleTransferType*)::MapViewOfFile(hmem, FILE_MAP_WRITE, 0,
0, FileSize);

// FileBuffer is read here...

 ::UnmapViewOfFile(FileBuffer);
 ::CloseHandle(hmem);

All works, but I'm concerned about memory leaks. This code is repeatably
used and I wonder what frees the memory used by these functions? The first
process closes all it's handles before the second process opens the memory
file, so I know the memory is still be held. When the first process is
called again and calls CreateFileMapping with the same name, does it re-use
the same memory, or does it allocate even more memory?

--
Regards;
Bruce Kingsley


Relevant Pages

  • Re: Programming in standard c
    ... Obtaining RMS file size? ... So why cant a function like filesize() be added? ... it has meaning. ... systems where this is sensible to do, there is going to exist a memory ...
    (comp.lang.c)
  • Re: Using memory mapped files to quickly transfer data between pro
    ... Does FILE_FLAG_NO_BUFFERING makes any difference for memory mapping? ... on the file and it displayed the data the first process had written to ... If you want to check whether disk IO is really happening you can ... This flag should only used with regualr file IO ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Programming in standard c
    ... you would not want to put this file into memory even if you ... This DBMS doesnt come with an API to update the database? ... The reasons for not including a function like filesize in the standard are getting funnier by the minute. ...
    (comp.lang.c)
  • Re: About some questions on PocketPC (CPU Usage,..)
    ... if the goal is to save data memory. ... There is *no swap file* in Windows CE. ... that won't get you the first process size. ... >>> Windows CE is not the same as desktop Windows, ...
    (microsoft.public.windowsce.app.development)
  • Questions on mapped files
    ... readonly and then simply access it via memory in my processes. ... this is the code I'm using to map my file: ... if I have my first process map the file and than pass his ... through the first processes pointer. ...
    (microsoft.public.windowsce.embedded)