views:

364

answers:

3

We're developing an application that will have a plug-in "architecture" to allow consumers of the app to provide their own proprietary algorithms. (We will basically have a set of parsers and allow third parties to provide their own as well)

The domain space requires very high performance, so out-of-process bindings are not going to work and we'd rather leave the heavyweight things like CORBA and COM alone.

Basically we're looking for a simple cross-platform wrapper around:

  • load library from a relative path
  • provide a mapping of the particular dll/.so to some configuration/name
  • do some initialization and query the library to ensure it provides the necessary functionality

I think this is really just a wrapping around loadlibrary() and the method calls exported. We can write this ourselves, but we'd rather use existing code as we have enough on our plate.

Again, throughput and performance are very very important.

Similar questions are:

http://stackoverflow.com/questions/960836/cross-platform-alternative-to-com - this one is close, but we want in-process only - no need for out of process and our needs are a little "lighter weight".

http://stackoverflow.com/questions/1235165/c-cross-platform-dynamic-libraries-linux-and-windows

This is for unmanaged C++ - we cannot use .NET

EDIT - what we found

We found that Poco works great for our needs. As a bonus This page is a much appreciated comment on the state of C++ development and the language direction...

It was a simple cross platform wrapping that we needed that Poco provides. Really there is not much to it, but still saves us time and testing. No additional overhead during run time.

+3  A: 

The ACE library contains wrappers for dynamic library loading that work cross platform. If you want more comfort than plain loadlibrary then look at TAO The ACE ORB. Using corba with TAO is extremly performant and most likely beats any self crafted plugin infrastructure especially if you use in process calls, as TAO optimizes them.

To use the dynamic library cross platform wrapper use ACE_DLL. It provides the most basic cross platform wrapper around loadlibrary() that you mentioned.

In between using ACE_DLL and using TAO is the service configuration framework of ACE that allows you to dynamically load objects. After loading you can get an upcast pointer to the loaded object that you implemented and can call any method on the loaded object.

The code to do that would look like this:

char const * const cpc_myClass = ACE_DYNAMIC_SERVICE_DIRECTIVE(
  "myclass",
  "dllname",
  "_make_MyClass",
  ""
);
result = ACE_Service_Config::process_directive(cpc_myClass);
MyClass * p_obj = ACE_Dynamic_Service<MyClass>::instance ("myclass");
p_obj->callAnyMethodYouLike();

Here is explained that TAO knows two types of colocation optimization (thru_poa and direct):

When using the direct strategy, method invocations on collocated objects become direct calls to servant without checking POA's status.

You might be amazed how effective TAO can be if used correctly. I suggest to create a simple proof of concept and do measurements.

lothar
I am familiar with ACE - I don't need the "heavyweight" cross process or cross machine bindings though. I can't imagine that ACE is anywhere near the performance of one virtual call. What is the overhead of an ACE call?
Tim
If you use the ACE_DLL class there are no cross process calls at all. Maybe you're not familiar enough with ACE? Even with TAO you can generate a 'direct' mapping that basically does just a virtual call when the called object is in the same process.
lothar
+1 Yes, I had used ACE as a corba implementation - not ace_dll - thanks for the suggestion
Tim
+4  A: 

You may be interested in Boost.Extension

Éric Malenfant
+2  A: 

I think this might also work: http://pocoproject.org/docs/Poco.SharedLibrary.html

Tim