Talk:Optimizing C++/Writing efficient code/Memory access

I believe these suggestions require some associated justification. In other words, there needs to be some text about "why" these things should be done. For example, why should local functions use an anonymous namespace be used instead of statically declared functions? Or why should memory access occur in ascending order? Furthermore, it'd be nice to know the relative benefit of each suggestion. For example, what performance gain is actually likely if a constructors arguments are re-ordered to declaration order in a class of only a half dozen simple member types? When it comes to "optimizing", a lot depends on the context of the optimization, therefore there needs to be some description of why/when a particular optimization makes most sense. I am not arguing against these being valid suggestions, but I do think they need associated rationales to convince the reader why and when they may be worthwhile. -- Autumnfields (talk) 18:49, 9 June 2010 (UTC)

I wrote the text and I don't think further explanation is required.

First, because the average programmer need just to know what to do and not why.

Second, because anyway enough information is explanation is provided.

Let's see your points.

You wrote "why should local functions use an anonymous namespace be used instead of statically declared functions?". And the module contains "in modern C++, the use of static global variables and functions is deprecated, and should be replaced by variables and functions declared in an anonymous namespace". It is not a question of optimization. To optimize the code, you could just as well use statically declared functions and variables. But it appears that they are deprecated, and therefore you'd better use an anonymous namespace.

You wrote "why should memory access occur in ascending order?". And the module contains "Data caches optimize memory access in increasing sequential order." It appears that usually hardware behaves that way.

At last you said "it'd be nice to know the relative benefit of each suggestion". That is quite hard to do, as it depends on a lot of factors. Actually, some advices have null or adverse advantage. Therefore, you should always time your code before and after applying a change meant to "optimize".

--Carlo.milanesi (talk) 16:16, 26 June 2010 (UTC)