ddh wrote:
[color=blue]
> When I
> do an inserting action, I think that an operator 'new' is called to
> allocate very little memory, so about 1500 times 'new' is called. Maybe
> it is the reason which make the action so expensive?
>
> Now my question is: is it worth to implement my own allocator to
> allocate memory in such a situation? And if it is worth, could you give
> me some advice about how to write an allocator?[/color]
It seems you might be looking for a "pool allocator".
(It's just a class calls new to get batches of say a 1000
items at a time, then hands them over one by one as you request).
You could consider just using a std::vector for your objects
(it doubles the allocated size each time it runs out, but does
reallocation and copying, which may or may not suit you.)
There are also several such libraries available,
so you don't need to write your own.
You could try the pool library in Boost, see
http://www.boost.org/libs/pool/doc/index.html
Look for the pool_alloc or pool_allocator object - it can be
used as a drop-in replacement for std::allocator.
Cheers,
homsan