Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass shared_ptr object to c++ function as pointer #467

Open
SergeyStrGroup opened this issue Jan 28, 2025 · 0 comments
Open

Pass shared_ptr object to c++ function as pointer #467

SergeyStrGroup opened this issue Jan 28, 2025 · 0 comments

Comments

@SergeyStrGroup
Copy link

SergeyStrGroup commented Jan 28, 2025

Hi!
Is it possible to take pointer from shred_ptr in julia?

I found the following behaviour:

Here is a binded class:

   types.add_type<DataBase>("DataBase")
      .method("AddMaterial", &DataBase::addMaterial);

    types.method("GetTemplate", [](DataBase *db, const std::string &name) -> PropTemplate 

Lets return raw pointer to DataBase:

    db = OpenDb()
    println(typeof(db)) # CxxPtr{DataBase}
    AddMaterial(db, "", InN)           # ok
    templ = GetTemplate(db[], "")  # ok

its ok.

Let return stdL::shared_ptr

    db = OpenDb()
    println(typeof(db)) # CxxWrap.StdLib.SharedPtrAllocated{DataBase}
    AddMaterial(db[], "", InN)         # ok
    templ = GetTemplate(db[], "")  # error

i got error trying to pass shared_ptr[] to non member function taking pointer.

Its obvious that operator[] return reference and there is internal workaround for members.

Is it possible to get it work same way for member and non member functions? (Could i add some function taking pointer from shared_ptr?)

(i have a lot of function taking pointers, and get 20% slow down on simple functions taking reference)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant