Hi Tony, On 11.01.2016 17:56, Tony Cappellini wrote: > > > I've already got a project built for Linux, using Boost-python. My > Python code can import the C++ extension and access the members that > are exposed. > > My C++ code needs to call fill in C++ structures in order to call > ioctl() functions, while passing the addresses of the structures to > the ioctl functions. > > I also need to allocate large (10's of MB - 100s of MB) buffers which > must be aligned to specific boundaries. A pointer to these buffers are > part of the above-mentioned C++ structs. > (I already have the C++ functions which handle the alignment and > memory allocation) > > The problems I'm facing are: > 1. How to initiate the memory allocation from Python, so that the > user has access to the > data after the ioctl() completes. This would eliminate the > need from copying the data from > C++ to Python, after each ioctl() call. > 2. Using boost-python, which type of Python data structure is > best suited to be shared across > the C++/Python boundary? Keep in mind that the allocation > needs to happen in C++ so that > memory alignment can be maintained, but initiating the > allocation/alignment will be done from > Python.
What you are describing all sounds quite feasible. > > Essentially- Python needs access to the return value from a malloc() call. Really ? Why ? You say your C++ code needs to access the pointer(s). Python has no notion of "pointer", but it will happily pass around whatever data you expose from C++. So let's say you have a C++ class (or struct if you prefer) that encapsulates the data and methods, such as: class something { public: something() : buffer_(allocate_memory()) {} void call_ioctl() { /*...*/} private: char *buffer_; }; if you expose the above class together with the constructor and the 'call_ioctl()' member function I think you have all you need. If not, please elaborate. Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig