17 Dec 2002 shughes   » (Journeyer)

I spent a good part of yesterday writing up a little bit of a "memory object cache" (whatever ;-), that preallocates objects, as to avoid insessant calls to malloc() for objects of the same size.

This is useful for example in a hash table, or linked list implementation, you usually have "buckets," elements that act as container for every element in the structure. By preallocacting these buckets you can gain a nice performance increase (on my little hash implementation, i gained an average of 25% improvement). Its also useful when implementing scripting languages (VHLL's, which is why I wrote it), when your language has a base type (for example in PHP, its a "zval"), that is really created and destroyed quite often, avoiding malloc'ing and free'ing a few thousand times is quite nice.

Anyhow, the code is quite small, and available at:

http://www.bumblebury.com/csexp101.tgz

the relevant files are

memobj/memobj.[ch]

and you can see the difference by::

time ./test.memobj
time ./test.normal

To implement it, I used a two dimensional array, that way you avoid fragmentation, and still have reasonable performance. I'll write up something a little more formal later..

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!