Tie::GHash

acme on 2001-06-14T15:40:29

First, check out the docs to Tie::GHash.

The story behind this module is interesting. This module was created during Brian Ingerson's Inline talk at YAPC::NorthAmerica 2001 when he asked me to code something fun using Inline, so blame him for this.

To be fair, I'd been thinking about the idea for this module for a while. Perl hashes take up a lot of memory, and occasionally you'd like to have huge hashes in memory (for Markov chains, say).

I had been aware that there were various different hash libraries around, so I picked a random one which was likely to be installed on a computer: the GNOME glib's ghash library. I checked out the API docs and it seemed fairly easy to use. I found an article explaining the rest of the details, and everything looked sweet.

Now I needed to code up a basic Inline module (using the new Inline::MakeMaker module). I did a simple h2xs incantation, changed the Makefile.PL to use Inline::MakeMaker and WriteInlineMakefile, set up a module as documented in Inline.pod, and then read the Inline::C cookbook to learn "How can I use Inline to make use of some shared library?".

While I could have provided an object-oriented version to these hashes, it was far better to make the hashes look just like Perl internal hashes. This can be acheived by tie-ing the hash - see the