May 22, 2000
Better Alternatives to a Custom Memory Manager
Some applications have special memory requirements. For example, they allocate large amounts of memory at once and then use it in parts, or they allocate only objects of the same type during their execution. In earlier stages of C++, the common solution was to overload the operators new and delete. However, this technique is error prone and is subjected to various inefficiencies. Today, you can use an STL container instead of a custom memory manager. Consider the vector template: you can “allocate ” objects on it by calling the push_back() or insert() member functions. Likewise, you can “delete ” objects by calling the remove() and erase() member functions. Remember that all STL containers have an embedded allocator a memory manager specifically optimized for that container. Therefore, an STL container usually provides better performance compared to a custom memory manager.