Tech Support > Microsoft Windows > Development Resources > CreateFileMapping() question
CreateFileMapping() question
Posted by indrawati.yahya@gmail.com on March 27th, 2007


Hi
I've just read on how to use CreateFileMapping() to share memory
between processes. I've created two programs to try it, and they seem
to work fine. I have one question about the API though: If I use the
data pointer obtained from MapViewOfFile() to write to the shared
memory, how much data can I write to this address without causing
undefined behaviour? If VirtualQuery() returns a
MEMORY_BASIC_INFORMATION with RegionSize set to x bytes, does that
mean I can write x bytes to that address?

Thanks!

Posted by Sten Westerback \(MVP SDK\) on March 27th, 2007



<indrawati.yahya@gmail.com> wrote in message
news:1174989286.775208.208800@y80g2000hsf.googlegr oups.com...
the MapViewOfFile call.
It does however depend on what you mean by undefined behaviour. If that was
a nice way of saying application crash then that shouldn't happen unless you
offset more than reserved in virtual memory. The other possibly behaviour
would be that writing much memory will cause system cache memory to fill up
and result in slowness for some time...

Also, did you notice the text "To guard against exceptions due to input and
output (I/O) errors, all attempts to access memory mapped files should be
wrapped in structured exception handlers." in the reference? Disk space or
network distruption can be valid causes of concern.

by the view.
So just use what you have reserved in last parameter of MapViewOfFile.

- Sten



Posted by indrawati.yahya@gmail.com on March 27th, 2007


Hi Sten, thanks for the reply. I am not clear about the above
statement. Does that mean that whenever I dereference, read, or write
to the shared memory pointer, I must wrap the code with __try and
__finally blocks? E.g.

__try
{
var = *sharedBuff //or
*buff = 5; //or
memcpy(buff, pData, len);
}
__finally
{
}

Is that correct? Thanks!



Similar Posts