Question

I know that when you load a dynamic C++ library using dlopen() you can then get pointers to functions inside that library, but is there a way to efficiently (performance matters) do it the other way?

I know that I could just call a function (when initializing the library) inside the library passing an array of pointers to functions, or just send the pointers all separately to a function. (although an array would probably be better because it allows me to add functions yet not require all old plugins to update)

I'm not really sure if this is efficient as there might be hundred functions and sending all of those to maybe 10 libraries might not be efficient.

But I am not very experienced with Dynamic Libraries so I am just wondering if you guys know of any better was to do this.

EDIT: Maybe put all those functions in a class and then send a class pointer trough a function call? Would that work?

Was it helpful?

Solution

"But I am not very experienced with Dynamic Libraries"

That's the cue to say: you don't want to do this.

Perhaps look at Boost Extension (not official part of boost), which takes the high-level, C++ approach here.

That said, most platforms support this to an extent. E.g. XlC++ on AIX has rtld (which requires an explicit 'exported' symbols map, IIRC), and I had the same working on windows and linux (our 3rd-party workflow engine required it). Sending the array of fptrs seems most pragmatic, and closer to the 'plugin' pattern.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top