[Debtags-devel] using libdebtags in libraries

Enrico Zini zinie@cs.unibo.it
Fri, 3 Sep 2004 12:07:20 +0200


--BXVAT5kNtrzKuDFl
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline

On Thu, Sep 02, 2004 at 03:57:19PM +0200, Benjamin Mesing wrote:

> what will happen if I use libdebtags in to different libraries which are
> dynamically loaded at runtime (i.e. plugins). Each of them calling the
> Environment::init() function?
> I have no experiences in working with libraries so I would appreciate
> all the tips I can get. There are two things to consider:
>       * Will there be two instances of the static Environment::instance
>         (resulting in a lot of wasted memory) and if so could it be
>         prevented without the libraries knowing each other (and also the
>         main program knowing nothing about the libraries).
>       * Will calling the init function do harm (I think not as it checks
>         for existence of the instance variable).
> Hope you can help me.

I have little experience with dynamic linking, but if the library is not
replicated in memory (resulting in having multiple instances of the
"instance" variable), the "if (instance == 0)" guard in the init
method would, as you said, protect about duplicated instantiations.

A problem in this case would arise if the various plugins would like to
call init with different arguments, like one plugin wants the library
with facet_only==false and the other one wants it with facet_only==true.

If instead the library is replicated in memory, then you would waste
memory, but everything should work fine (that is, the library is not
doing locks or accessing some non-sharable resource.

If you're already familiar with dynamic loader code, you could try
adding a printf inside the if in the init method and then trying to call
two stub libraries that call init, to see how many times it gets called.

Please let me know if you need changes to the library to support
plugins.


Ciao,

Enrico

--
GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <enrico@debian.org>

--BXVAT5kNtrzKuDFl
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBOEJY9LSwzHl+v6sRAmynAJ4omS2D3sPwEEhB8MuHsjeQlvfEAACaA2IL
88ON9Yj70/omhMmyxHUkZvY=
=wufj
-----END PGP SIGNATURE-----

--BXVAT5kNtrzKuDFl--