I would like to share memory between C++ and Python.
My problem:
Is there any way to "map" memory corresponding to C++ variables so that I may access the data from Python? I don't want to copy 6GB of data onto a hard drive.
First path : I think the more appropriate way for you to go is ctypes . You can create a shared library, and then load the functions of the shared library in Python, and fill all the data containers you want in Python.
In Windows, you can create a DLL, and in Linux you can create a shared .so library.
Now this has the advantage that this will be independent of your Python version.
Second path : I think it's less appropriate but you can get it to work, which is the Python C Extension . With this, you can call Python data containers ( PyObject
s) and fill them inside C.
However, the code you compile here will always need to be linked to Python libraries.
Which one to use? :
With both options, you can transfer huge blocks of memory between C++ and Python without necessarily involving any disk read/write operations.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.