Python use of pointers when calling C++dll via Swig

Source: Internet
Author: User

When the interfaces of Python and C + + involve buffers, you can create buffers in Python and pass pointers to the buffers to C + + functions (by creating additional functions for conversion). Examples are as follows:


Python side:

1. Get the binary data represented by STR (read files, etc.).

2. Create a buffer using the Create_string_buffer (str) function in the cTYPES package.

3. Get the buffer address represented by INT, take advantage of the AddressOf (BUF) function, buf the buffer object created in 2.

4. Use the extra conversion function INT2VOIDP (address) function to convert int to the buffer address of a C + + void*,address that is obtained by int in 3.

5. Pass the resulting Void* object to the C + + function.



C + + side:

1. Use void* from Python to make calls, or convert to char*.

Python use of pointers when calling C++dll via Swig

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.