views:

578

answers:

6

We have developed a number of custom dll's which are called by third-party Windows applications. These dlls are loaded / unloaded as required.

Most of the dlls call web services and these need to have urls, timeouts, etc configured.

Because the dll is not permanently in memory, it has to read the configuration every time it is invoked. This seems sub-optimal to me.

Is there a better way to handle this?

Note: The configurable information is in an xml file so that the IT department can alter as required. They would not accept registry edits.

Note: These dll's cater for a number of third-party applications, It esentially implements an external EDMS interface. The vendors would not accept passing the required parameters.

Note: It’s a.NET application and the dll is written in C#. Essentially, there are both thick (Windows application) and thin clients that access this dll when they need to perform some kind of EDMS operation. The EDMS interface is defined as a set of calls that have to be implemented in the dll and the dll decides how to implement the EDMS functions e.g. for some clients, “Register Document” would update a DB and for others the same call would utilise a third-party EDMS system. There are no ASP clients.

My understanding is that the dll is loaded when the client wants to access an EDMS operation and is then unloaded when the call is finished. The client may not need to do another EDMS operation for a while (in some cases over an hour).

+1  A: 

Use the registry to store your configuration information, it's definitely fast enough.

Greg Hewgill
The IT department has no cause to complain. If necessary prepare a tool that edits the relevant registry values, BUT the registry is the best place to store configuration information on the windows platform. There are even tools that edit the registry remotely. And its securable.
Chris Becke
A: 

Why don't you let the calling application fill out a data-structure with the stuff you need? Can be done as part of an init-call or so.

Nils Pipenbrinck
+1  A: 

I think you need to provide more information. There are so many approaches at persisting configuration information. We don't even know the development platform. .Net?

  1. I wouldn't rely on the registry unless I was sure it would always be available. You might get away with that on client machines, but you've already mentioned webservices.

  2. XML file in the current directory seems to be very popular now for server side third-party dlls. But those configurations are optional.

  3. If this is ASP, Your Trust Level will be very important in choosing a configuration persistance method.

  4. You may be able to use your Application server's "Application Scope". Which gets loaded once per lifetime of the application. Your DLL can invalidate that data if it detects it needs too.

  5. I've used text files, XML files, database, various IPC like shared memory segments, application scope, to persist configuration information. It depends a lot on the specifics of your project.

Care to elaborate further?

EDIT. Considering your clarifications, I'd go with an XML file. This custom XML file would be loaded using a search path that has been predefined and documented. If this is ASP.Net you can use Server.MapPath() for example to check various folders like App_Data. The DLL would check the current directory for the configuration file first though. You can then use a "manager" thread that holds the configuration data and passes it to any child threads that require it. The sharing can use IPC like a shared memory segment.

This seems like hassle, but you have to store the information in some scope... Either from disk, memory ( application scope, session scope, DLL global scope, another process/IPC etc. )

ASP.Net also gives you the ability to add custom configuration sections to standard configuration files like web.config. You can access those sections at will and they will not depend on when your DLL was loaded.

Why do you believe your DLL is being removed from memory?

kervin
A: 

How often is the dll getting unloaded? COM dlls can control when they are unloaded via the DllCanUnload method. If these are COM components you could look at implementing some kind of timeout here to prevent frequent loads and unloads. Unless the dll is reload the configuration at a significant frequency it is unlikely to be a real performance bottleneck.

Knowing that the dll will reload its configuration at certain points is a useful feature, since it prevents the users wondering if they have to restart the host process, reboot the machine, etc for the configuration to take effect. You could even watch the file for changes to keep it up to date.

Rob Walker
A: 

I think the best way for a DLL to get configuration information is via the application that is using it - either via implicit "Init"-calls, like Nils suggested, or via their configuration files.

DLLs shouldn't usually "configure themselves", as they can never be sure in which context they are used. Different users (as in applications) may have different configuration settings to make.

Since you said that the application is written in .NET, you should probably simply require them to put the necessary configuration for your DLL's functions in their configuration file ("whatever.exe.config") and access it from your DLL via AppSettings or even better via a custom configuration section.

Additionally, you may want to provide sensible default values for settings where that is possible (probably not for network addresses though).

Christian.K
A: 

If the dlls are loaded and unloaded from memory only at a gap of every 1 hour or so the in-efficiency due to mslal initializations (read file / registry) will be negligible.

However if this is more frequent, a higher inefficiency would be the physical action of loading and unloading of dlls. This could be more of an in-efficiency than small initializations.

It might therefore be better to keep them pinned in memory. That way the initialization performed at the load time, does not get repeated and you also avoid the in-efficiency of load and unload. You solve 2 issues this way.

I could tell you how to do this in C++. Not sure how you would do this in C#. GetModuleHandle + making an extra a LoadLibrary call on this handle is how i would do this in C++.