Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Delaying module initialization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Delaying module initialization

I have a problem with module initialization which manifests itself in
perl4caml (thanks to Alaine Frisch for pointing this one out).

Basically the perl4caml.cma / .cmxa library consists of lots of
wrapper modules such as Pl_Template which wraps Perl's Template, and
Pl_LWP_UserAgent which wraps LWP::UserAgent, etc.

Each of these wrappers has to 'use' the corresponding Perl library
when it is initialized.  Each wrapper module has code similar to this:

open Perl
let _ = eval "use LWP::UserAgent"

This is just a requirement of Perl, that you have to 'use' a library
before you can actually use it.

Now the problem is that any program which links with perl4caml.cma
appears to immediately 'use' every Perl module, even ones for wrappers
which the program doesn't actually need.

This has two bad consequences: (1) Large amount of memory is consumed
at start-up.  (2) If you move the Perl library onto another machine
(eg. if it's compiled and bundled into a .deb), then the library won't
work unless all the corresponding Perl modules have been installed,
which is very inconvenient.

One way around this would be to force users of modules to explicitly
initialize the wrapper, eg. by calling Pl_LWP_UserAgent.init () at the
start of their program.  But if they forget to do this, then bad
things can happen.  Another way would be to split the library into
individual .cmos, although this might be inconvenient, and there are
also tricky dependency issues - Eg. what if a wrapper depends on other
wrappers being around?  In Perl everything is dynamic so one library
can depend on another library which doesn't exist, and as long as the
other library isn't used, everything will be fine.  This is not the
case with OCaml.

Does anyone have any other ideas how to solve this?

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
C2LIB is a library of basic Perl/STL-like types for C. Vectors, hashes,
trees, string funcs, pool allocator: http://www.annexia.org/freeware/c2lib/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners