Skip to content

Use cast to get a reference to the underlying C++ object #5484

Closed Answered by leakec
leakec asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, found a way to answer my own question here. In the end, I was making a silly mistake. Let me explain.

pybind11 has the concept of a value and a holder. The holder is the thing being used to manage lifetimes, a shared_ptr in this case. pybind11 often works with the raw pointer, which is called the value. For example, when you access your object to call its methods, etc. from Python, pybind11 is calling these methods, etc. on a cached raw pointer, i.e., on the value. This avoids calling things like get each time on the holder, which improves performance.

The idea with the pybind11 API is you don't need to get the holder that pybind11 is storing. You can get copies and such, but there'…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by leakec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant