tdegeus / pybind11_examples

Examples for the usage of "pybind11"
MIT License
633 stars 89 forks source link

Pass std::vector without copy #12

Open petrasvestartas opened 1 year ago

petrasvestartas commented 1 year ago

Hi,

In your examples of std::vector, data is copied.

Is there any example that shows how to bind vectors by reference instead of copy?

tdegeus commented 1 year ago

This example passes a list by reference : https://github.com/tdegeus/pybind11_examples/blob/master/01_py-list_cpp-vector/example.cpp

petrasvestartas commented 1 year ago

Dear @tdegeus ,

By returning the output, doesn't it copy the data to a new vector?

tdegeus commented 1 year ago

Ah @petrasvestartas . Ah yeah you are right, I did not look further than the input as I assumed your question to be about that. What is your question then actually about:

Or is your question about yet something else?

petrasvestartas commented 1 year ago

The second. I think the only way to do this is by using opaque option from pybind11.