Linked by Zachary Pinter on Tue 27th Apr 2004 17:09 UTC
General Development Garbage collection (GC) is a technology that frees programmers from the hassle of explicitly managing memory allocation for every object they create. Traditionally, the benefit of this automation has come at the cost of significant overhead. However, more efficient algorithms and techniques, coupled with the increased computational power of computers have made the overhead negligible for all but the most extreme situations.
Permalink for comment
To read all comments associated with this story, please click here.
Memory Pools
by Jonathan Bartlett on Thu 29th Apr 2004 18:35 UTC

The most often overlooked form of memory management is memory pooling. It's not a universal technique, but it works in many situations, and is used in Samba and Apache at least.

Pooling is lifecycle-based memory management. When you know which parts of your application's lifecycle a structure will be in, you can create a "pool" of memory which will all be freed at the end of that part of the lifecycle.

For example, Apache has memory pools for the lifetime of the server, the lifetime of the connection, the lifetime of the request, and others. If you allocate memory that you know will not be used past the end of the request, you allocate it in the request pool. Then, all objects in the request pool are freed simultaneously at the end of the request. This is by far the fastest method of memory management, because mallocs() and frees() are constant-time and very fast. Pool allocation is about the same speed as normal malloc().

There are two reusable implementations of this I'm aware of: Apache's portable runtime and GNU's obstack library. However, it's a very powerful technique if your application fits that model.