C++ and Embedded Python

J

jasonkeddie

Is there a method to allow a pointer to an object in local memory to
be shared with embedded Python within a C++ executable?

The reason I require this is I have a C++ instance of a class that has
data memers that are themeselves pointers to other object types. It is
a fairly complicated object.
In an ideal world I would just pass this pointer into an instance of
the Python interpreter. This would allow the python program access and
change some properties of this object instance, then pass it back to
the calling C++ program. I would use this same system to pass messages
between the C++ (calling program) and the embedded Python interpreter.

I have looked at using shared memory, which will work until you
require embedded pointers within your object as you cannot dynamically
allocate memory in a shared space.

Any help is much appreciated.
 
S

Stefan Behnel

(e-mail address removed), 20.01.2012 14:52:
Is there a method to allow a pointer to an object in local memory to
be shared with embedded Python within a C++ executable?

The reason I require this is I have a C++ instance of a class that has
data memers that are themeselves pointers to other object types. It is
a fairly complicated object.
In an ideal world I would just pass this pointer into an instance of
the Python interpreter. This would allow the python program access and
change some properties of this object instance, then pass it back to
the calling C++ program. I would use this same system to pass messages
between the C++ (calling program) and the embedded Python interpreter.

I have looked at using shared memory, which will work until you
require embedded pointers within your object as you cannot dynamically
allocate memory in a shared space.

Do I understand correctly that you only have one instance of a Python
runtime, embedded in a C++ program? If that's the case, I don't see the
problem. Just create an extension type to model your API towards the C++
objects and pass data back and forth. Cython will make that easy.

I specifically do not see why you would care about shared memory here. If
both parts of the application (i.e. Python code and C++ code) are in the
same process, they will usually be able to access the same memory without
any special setup.

If I misunderstood your intention, please provide more details, including
the steps you undertook so far and a specific description of what didn't
work. You may also want to provide some hints on what kind of data you want
to exchange and what both sides will do with it.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top