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..
