Reputation: 41
The question is related to a talk by Stefanus Du Toit on hourglass pattern. Its a great talk, really helpful for library writers.
Youtube Link: https://youtu.be/PVYdHDm0q6Y
Slideshare Link: http://www.slideshare.net/StefanusDuToit/cpp-con-2014-hourglass-interfaces-for-c-apis
Ok here is the question:
Say I have to pass a std::vector<MyObject>
across the library boundary. What is the best way to do this using hourglass pattern. I am concerned about the performance as well as keeping a clean interface. Given below is a set of example interfaces that I want to implement.
Clientside C++ interface:
void MyLibraryClass::DoSomething(const std::vector<MyObject>& objs);
C Interface:
???? (Not sure what is the best practice here)
Internall library C++ interface:
MyInternalLibraryClass::DoSomething(const std::vector<MyObjectImpl>& objs);
Hope this explains my question.
Upvotes: 4
Views: 336
Reputation: 134
Best would to pass an array internally:
void do_something(MyObject* array, size_t count);
The internal class use something like std::span
in its interface, since you are not modifying the vector, it would be more flexible and shouldn't require that much code changes.
Upvotes: 0