Shared library

This is an old revision of Shared library, edited by Marcov at . The current revision is 40400.

(here if I say shared library I mean both .so as .dll, unless I really say "unix shared library" or "dll")

Currently there are a lot of Shared libraries bug reports. However, to my knowledge there is no real documentation about how shared libraries work in combination with FPC. That is both how shared libraries work now, how they should work, and how Delphi treats them.

Let's start with a simple sketch of what forms Delphi supports, because we will of course try to be as compatible as multiplatformwise reasonable. Note that this is all from memory and webpages. If you can detail it more, or specify more exact borderconditions, by all means, do)

Delphi

Delphi to my knowledge knows three (or four) ways of dynamic linking.

Besides these, Delphi can also generate dlls that are ActiveX components. T.B.D.

Sharemem implemntation details

As said, sharemem switches the memory manager to a global one. Under Windows this is afaik the COM manager. On *nix a similar memmanager doesn't always exist ( Gnome and KDE component architectures might have something similar), but it is not guaranteed there.

One could probably simply have all programs use cmem, which could be a "level 0" implementation for everything that runs in this process.

VMT duplication

I've heard various opinions about if VMT duplication is a real problem when passing classes between DLL and mainprogram (for the various scenario's). I don't exactly know when it is a problem or not. (if you do, feel free to explain it here). Therefore I just list for all possible scenario's if VMTs are duplicated or not.

In earlier discussions about packages, there was some confusion about this topic. People assumed that packages would somehow tap into the RTL VMT's in the main binary. I'm however pretty sure this is not the case, at least not in Delphi, since when using packages, the RTL always is a package too. And every dependancy of an unit in a package must be in the same package or in a package it has a dependancy on. This means an unit only exists once in the greater program (main program + its packages)