I have a problem that has stumped me involving memory mapping, and interchange between C++ (Visual Studio under Win7 32bit) and Python 2.7.
In my C++ code I have a large (2Mbyte) image that updates at about 25Hz. I share this with another C++ .exe happily.
The C++ code is (extract only)
TCHAR szFrameName[]=TEXT("IoAAOLICameraCameraFrame");
and
// create mapped shared memory for the exposed frame data
hFrameMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
nCameras*sizeof(IoAFrameBuffer), // maximum object size (low-order DWORD)
szFrameName); // name of mapping object
if (hFrameMapFile == NULL)
{
_tprintf(TEXT("Could not create framebuffer file mapping object (%d).\n"),
GetLastError());
return;
}
pFrame = (IoAFrameBuffer*) MapViewOfFile(hFrameMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
nCameras*sizeof(IoAFrameBuffer) );
if (pFrame == NULL)
{
_tprintf(TEXT("Could not map view of framebuffer file (%d).\n"), GetLastError() );
CloseHandle(hFrameMapFile);
return;
}
All works fine. The data are shared and the images come through just fine.
However for good reasons I want to pick up from the mapped memory under Python. So I have:
import mmap
import os
file = os.open(unicode('IoAAOLICameraCameraFrame'),os.O_RDWR)
fpx = mmap.mmap (file.fileno(),0)
Doesn't matter whether I use the above with or without unicode in front of the map share name. Always returns:
OSError [Errno 2] No such file or directory.
SO: Problem seems to be the way the memory mapped file is named. It only exists in the copmuter memory (non-persistent mapped file), so path names such as C:\IoAAOLICameraCameraFrame will not work.
Where am I going so badly wrong? Is there any way to look at the names and characteristics of these mapped objects under Win7?