I am working on a plugin for an application, where the memory should be allocated by the Application and keep track of it. Hence, memory handles should be obtained from the host
STL containers use an allocator they are given at construction time, with a default allocator that uses operator new
and operator delete
.
If you find the default is not working for you, you can provide a custom allocator that conforms to the container's requirements. There are some real-world examples cited here.
I would measure performance using the default first, and optimize only if you really need to. The allocator abstraction offers you a relatively clean way to fine-tune here without major redesign. How you use the vector
could have far more performance impact than the underlying allocator (reserve()
in advance, avoid insert and removal in the middle of the range of elements, handle copy construction of elements efficiently - the standard caveats).