malloc pooling is a technique for more memory-efficient allocation of a lot of small data structures. Let's say, for example, that you have a program that must process a huge number of points, and you represent these points, in C++, as objects with X and Y coordinates. To create a new point object, you just use the good old new operator, right?

Unfortunately, the new operator uses the malloc function internally, and and most implementations of malloc have some overhead that they don't tell you about: they keep a little bit of information -- say, four bytes -- right before the pointer they return. This is a count of how big the block is, so it can be deallocated easily. However, this really adds up if you have a lot of tiny objects in your program.

The solution to this is fairly simple: allocate a big block of memory beforehand, then put a bunch of objects in there. If you run out of memory in the block (here comes the fun part) you just allocate another block, perhaps putting all the blocks in a linked list. In C++ this can be done by overloading the new operator. In plain old C, this can be done by making a special function that will act like malloc, but only use malloc when it needs to make a new block.

Aside from using less memory, this is also hugely faster than using malloc a lot.

Log in or registerto write something here or to contact authors.