D
ddh
Hi,
I have a map type such as std::map<int, int>, which I used to manage
many values in a fixed order. But I have thousands of values to be
inserted into the map, and in some case, the action of inserting and
re-building is very frequent, that say, many times per second.
I've made some tests to insert 1500 values into a map, it cost about
30ms in my athlon XP1800+. I think it shouldn't be so expensive. 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?
Thank you very much for your help
I have a map type such as std::map<int, int>, which I used to manage
many values in a fixed order. But I have thousands of values to be
inserted into the map, and in some case, the action of inserting and
re-building is very frequent, that say, many times per second.
I've made some tests to insert 1500 values into a map, it cost about
30ms in my athlon XP1800+. I think it shouldn't be so expensive. 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?
Thank you very much for your help