2 ms·
This code is not only non-optimal, but also inneficient. First, it does a linear search - O(n) time - because it keeps adding null pointers for elements that a
by leovonl 11y ago
This code is not only non-optimal, but also inneficient.
First, it does a linear search - O(n) time - because it keeps adding null pointers for elements that are removed from each list. This makes literally no sense. Just removing the null pointer insertion would already improve the performance a lot.
Second, the multiset is also a poor choice for the available objects list, given its performance characteristics. A structure like a deque, with O(1) insertion/removal on both ends, would be much more suited for the job.
There are a few papers/presentations on memory allocation for C++ from Andrei Alexandrescu, like this one: http://nwcpp.org/talks/2008/memory-allocation.screen.pdf http://nwcpp.org/talks/2008/memory-allocation.screen.pdf
I'd suggest giving them a read, they give some good insights about simple yet very powerful techniques for improving memory allocation with little code.