Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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?
Posted
Updated 26-Aug-14 5:55am
v2

you should use a full path to ensure that it is found. And both processes shuld run with the same privileges (user).
 
Share this answer
 
But what is the path to an object that only exists in memory, never on a physical device and evaporates as soon as the data generating process terminates? Still don't know what to do!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900