Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Cross-platform DBM equivalent?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-02 (10:03)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Cross-platform DBM equivalent?
> I am developing an application that needs fast access to persistent
> configuration data, and I thought that DBM might be a good way to
> provide that functionality ... but I see that DBM isn't available on
> Windows.

As others mentioned, you could compile the C sources for a DBM
implementation on Windows, then build the Caml/DBM binding.

> Is there something similar that works on all platforms? Or an
> alternative approach?
> By the way, I'm at an early prototyping stage, so I can't be much more
> specific about my needs. What I can say at this point is that speed is 
> important; I think I need a key-value data structure, and it's probably
> okay for the types of both keys and values to be limited to strings, as
> with DBM.

I guess it all depends on the number of key-value pairs:

- For a few hundred entries, just parsing a plain text file is very
fast, e.g. using an ocamllex-generated lexer to do the parsing.  Plain
text files also make debugging easier.

- Up to 10^5 entries, input_value of a hash table or a "map" is quite
fast, e.g. less than 0.1 seconds.  This is what I use in the
SpamOracle mail filter to read the database of word frequencies.

It is true that the binary format used by input_value may change in
future OCaml releases, but so does the format of DBM databases, and
the input_value format hasn't changed in incompatible ways since 1996
or so :-)  Still, it is prudent to support conversions between
input_value form and some textual, portable form.

- Beyond 10^5 entries, either DBM or a real database (such as MySQL)
seems best.  Remember that DBM files are quite large, so an SQL
approach might be more effective.

Hope this helps,

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: