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

Simple example #4

Open
gitboy16 opened this issue Jan 17, 2022 · 2 comments
Open

Simple example #4

gitboy16 opened this issue Jan 17, 2022 · 2 comments

Comments

@gitboy16
Copy link

Hi, thank you for the package.
Someone mentionned your package:
https://discourse.julialang.org/t/ccall-c-sort-vector-of-string/74635/21

I was wondering if you would be able to provide a simple example (step by step) on how to sort a vector of strings using c++ std::sort.
Thank you

@eschnett
Copy link
Owner

As described on Discourse, this question is somewhat ill-posed, i.e. there are details missing. Calling C++ requires handling many low-level details, and you still need to handle them when you call C++ from Julia. Such questions are:

  • Would you represent the vector and the string using Julia types or C++ types? Or can they be copied and converted for the call?
  • If these are C++ types, who owns them (who is responsible for deallocating them)? Are you passing pointers, references, copies, or would you use std::shared_ptr or std::unique_ptr?
  • Do you want to compare the string using Julia's string comparison or the C++ string comparison method?

If you are thinking of an existing C++ library, then looking at the library's API might help answer these questions.

If you are unfamiliar with the questions above, then some higher-level questions might help determine the answers:

  • Who creates (allocates) the vectors and strings? Julia, or the library?
  • How much time do these vectors and strings spend in C++? Are they only briefly passed for processing, or is the C++ library keeping them around for much longer?
  • How generic is the C++ library? Can it handle arbitrary vector or string types, or does it basically have to be std::vector and std::string? (Or are these actually C types, as in const char *vec[10]?

@gitboy16
Copy link
Author

gitboy16 commented Jan 17, 2022

I'll try to answer your questions but if you need more information please let me know.
-Julia creates/allocates the vectors
-The vectors are passed to C++ for processing and then sent back to Julia for more processing. Once sent back to Julia, C++ does not need to keep these vectors.
-The library handles std::vector<std::string> types only.

Thank you

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

2 participants