ing is a technique
for more memory
of a lot of small data structure
s. Let's say, for example, that you have a program
that must process
a huge number of point
s, 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
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.