[C++-sig] Passing memory allocated in C++ to Python

Tony Cappellini cappy2112 at gmail.com
Tue Jan 12 12:52:20 EST 2016


Stefan,


To: cplusplus-sig at python.org
Subject: Re: [C++-sig] Passing memory allocated in C++ to Python
Message-ID: <56945036.8080302 at seefeld.name>
Content-Type: text/plain; charset=windows-1252

> 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
>>atever data you expose from C++.

Sorry about that Stefan, my post should have been clearer.

I know Python doesn't know about pointers.
I should have said "Python needs access to the memory pointed to by the
memory allocated with malloc()".


>>f you expose the above class together with the constructor and thei
>>'call_ioctl()' member function I think you have all you need.

In your something class, the data type returned from allocate_memory()
needs to be something that Python understands. Since that allocation
function (member) will be allocating 100s of MB of memory, how will this
memory map to a Python data type?

Is a bytearray better to use than a list (as far as performance is
concerned)? Is a list better to use than a string (as far as performance is
concerned). Are there other data types that should be considered?

The user will need to access that data as bytes, words, longs, and possibly
sequences.

I've tried using boost's extract, to convert the char * returned from
malloc() into a Python string,
and a Python list, but these result in compile errors.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20160112/2348b391/attachment.html>


More information about the Cplusplus-sig mailing list