Pages

Feb 11, 2014

Going dynamic

The Fortran people seem to really like the static libraries, why I couldn't really fathom. The idea behind a shared object (or dynamic library in Windows) is quite simple — flexibility. Their explanation is that static libraries (basically an object file) provides all that you need for linking and doesn't cause the problems loaders do. This is not quite true and there are some problems though:
  • If you link against a shared binary in the static library code, the linker has no way of incorporating it, thus creating references exactly like these you have in a dynamic library.
  • When you want to change something in a statically linked code, you have to rebuild the whole thing.
  • (Especially in Linux/Unix) The code is really shared(!), meaning a lot of applications use the same binary, changes in that binary propagate to all and additionally there is only one copy of each one binary unit.
Now dynamic linking is not without cost:
  • A person should ensure binary compatibility of the library as to be able to change the implementation without rebuilding the user applications. This could be quite a bit of work, especially for people who don't have a good set of habits for doing it.
  • You should ensure all the dependencies are in a place known to the loader.
  • Resolving of symbols may be done by the runtime as it is in Linux/UNIX.
  • The library interface and exports should be enforced, as in Linux/UNIX by default all symbols are exported, while in Windows none of them are.
All in all dynamic libraries require a bit more consistent and rigid design, while static libraries could be less fuss. In the long rung though, the advantages of dynamic linking are overwhelming and it is the better way, allowing you to be flexible about your code.

Jun 25, 2011

A Gaussian is a Gaussian

Interestingly a sum of Gaussian distributions is again Gaussian distribution. It didn't came as a big surprise to me, but my thesis adviser was truly amazed ... strange. Furthermore it holds true for both uncorrelated, and correlated statistics, and the rule for addition is impressively simple.

So let's say that we have two Gaussian distributions:



Then the sum distribution is simply:


Where for the parameters holds:



In the last formula rho is the correlation coefficient, with value defined as:

Jun 10, 2011

Exceptions

Before writing the final post on Wiener deconvolution, I decided to share a little code snippet. It occurred to me that from time to time I write an exception class. Mostly they are the same, so why not make it public ... It can be derived of course to provide further specialization, but for the current project I'm working on (which is a console application) it's enough.

So here goes the code:
http://codepad.org/KGvqarqa