python与c进程间通讯,与内存映射的C ++ / Python进程间通信

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?

解决方案you should use a full path to ensure that it is found. And both processes shuld run with the same privileges (user).

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值