|
Boost : |
From: Jeremy Pack (rostovpack_at_[hidden])
Date: 2008-07-08 18:34:42
Robert,
The first answer in my e-mail applies then - you can use the same
factory_map for as many shared libraries as you'd like.
Other answers below:
> Thanks for responding Jeremy.
>
> I'm a little confused about your response, but perhaps that's because
> I don't know as much about shared libraries as I should. Basically,
> I'm assuming that the shared libraries must remain open in order to
> continue to use the factories.
Yes.
> I'm not sure what you mean by closing
> the shared libraries I'm not using.
If you have no need to close the shared libraries (ie, you aren't getting
low on RAM), then don't. You should only need that if you are loading many,
many shared libraries. By default, they remain open.
> I'm technically using the shared
> libraries every time I call factory::create(). However, once I
> concatenate the factory_map for each shared library, I do not use the
> factory_map any longer. I simply keep them stored in a
> boost::ptr_vector to maintain lifetime, and when I no longer need
> access to my concatenated list of factories, I simply destroy the
> ptr_vector of factory_map objects.
1 - The factory object is copyable - so you can just copy all of the
std::map objects returned by factory_map::get into another map. You can then
safely destroy the factory_map.
2 - You can just use a single factory_map anyway.
Say, for example, I load 3 shared libraries. As I add more shared
> libraries, I am capable of creating more types, since each shared
> library provides a way for me to extend the capabilities of my factory
> (lets it create more types). In the case of having 3 shared libraries,
> the m_factories member would simply be 3 in size. I do not use the
m_factories member anywhere, it simply serves the purpose of
> maintaining the lifetime of the shared libraries.
You don't need to do that to maintain the lifetime of the shared libraries.
factory_map does not open or close shared libraries. Only the shared_library
object does that. By default, shared libraries are left open forever (this
is an option in the shared_library constructor). Feel free to delete
factory_maps as soon as you have retrieved the factories that you need.
If you could explain in more detail what you mean by using the same
> shared_library for multiple libraries, I would appreciate it. I
> figured there was a 1-to-1 mapping between factory_map and DLLs (on
> windows).
> ____________________________
>
Check out the example in
libs/extension/examples/multiple_inheritance/main_mi.cpp.
It does something like this:
factory_map my_map;
load_single_library(my_map, "first_library.extension", "extension_export");
load_single_library(my_map, "second_library.extension", "extension_export");
load_single_library(my_map, "third_library.extension", "extension_export");
Thus, it uses the same factory_map for every shared library.
If you only want the factories of a certain type (and delete the rest of the
factory_map), you can then do the following:
factory_map *my_map;
load_single_library(*my_map, "first_library.extension", "extension_export");
load_single_library(*my_map, "second_library.extension",
"extension_export");
std::map<std::string, factory<computer> > factory_list;
factory_list.swap(my_map->get<computer, std::string>());
delete my_map;
I think that in your case, this is what you want to do. Does that make more
sense?
Jeremy Pack
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk