Quote:
Originally Posted by
Hermit
TheCPUWizard is certainly correct on the point that it is senseless to use anything but the default allocator unless you are sure that it would be advantageous in a specific scenario. I do not, however, think you need to go as far as to run benchmarks in order to reasonably ascertain that high-frequency small object allocations can benefit from a special allocator (at least one from as reputable a vendor as Intel).
The real argument here apparently rises from the question of whether or not it is reasonable to write performance-conscious code even when doing so does not have a meaningful impact on the overall performance of the program (with respect to performance constraints that actually matter to users of the software, not just arbitrary benchmarks). I'll side with _uj here in saying that, even if the advantages are slim, if there are no disadvantages to a particular design decision then why not go with it? Are there really any disadvantages to using a well-tested third party allocator? I don't think the point made by TheCPUWizard regarding the risks involved was at all accurate (the example he cited regards home-brew, not reputable third party code). If there were a downside, I would say that using a non-standard library for small object allocation may incur some (probably small) cost when it comes to training new employees, and only because this probably reflects a broader company policy of using third party libraries for things normally done by standard ones.
So my overall point is that if you want to use a small-object allocator for (gasp) small object allocation, that's probably fine. Don't get the idea that OO in C++ is doomed without it though.
Hermit,
Thanks for the comments. From a qualitative standpoint I basically agree, but the lack of a quantitative basis concerns me.
1) "If there are no disadvantages". I have yet do come across ANY designs or implementations that meet this criteria, in any domain. There is invariably some set of trade-offs in any decision process.
2)"performance-conscious code even when doing so does not have a meaningful impact". Taken to extremes, is it worth spending an extra day of development to save 1mS off of a 10 second operation? How about spending 10 minutes to cut a 10 second routine down to under 1 second? For these the answer is (almost) obvious. But the "grey area" inbetween is much more substantial. My conclusion has been that the only reliable and effective methodology is to establish performance specifications and monitor performance against these specifications. This has been validated by the majority of client firms who have adopted this process.
3)"some (probably small) cost when it comes to training new employees" My experience has been that the cost of training can be well over $20K to train a team in the use of a new library (that represents less than one week for a team of 10) - so the very definition of small can mean wildly different things for different environments. What even this figure does not include is the time, or the risk of mistakes which may result in an additional QA cycle or even a bug in the final product.
4)"a well-tested third party allocator?"The allocator may be well tested. But my concerns are with replacing the DEFAULT allocator. This means it will be used with (potentially) all of the other third-party code (eg control libraries). In general there will have been NO testing of THAT codebase with the replacement allocator. The libraries may contain bugs which are not visible will the original allocator (or with different replacement allocators that the vendor might have tested).
5)"So my overall point is that if you want to use a small-object allocator for (gasp) small object allocation, that's probably fine." I have NEVER said anything against using specialized allocators for specific tasks. My earlier post walked through exactly how the Boost Library accomplishes this.
There is no doubt that my background influences my attitude and approach.
Coming from a military/space/industrial background where true real-time performance ["No good to shoot where the plane was"] and reliability (I have worked on many projects where a failure of a system would directly result in loss of life), has instilled a bedrock of making accurate measurements over the entire lifecycle.
Running a small company for a quarter of a century, has highlighted how devastating a "suprise" (defect, missed deadline, etc) can be. It has also shown how these can be magnified for the larger companies that have been my client [At the end of 2007 I was engaged on a project with a $4 million penality if the product was not delivered in working order on Jan 3rd 2008. A one day slip would have triggered the penality, as would any single bug that caused it to fail acceptance testing]
The result is that I strive to do everything within my power to minimize risks while meeting the requirements of a project. And within this context, I will maintain that replacing the default allocator without comprehensive measurements and testing, increases the risk, without providing a known overall advantage to the functionallity, reliability, or maintainability to the final application.