100% QQ type, as defined in https://bintanvictor.wordpress.com/2017/02/15/qqzz-mutual-exclusion-cjava/.I feel many are micro optimizations with questionable improvement. I wonder how much value such obscure knowledge adds to the team.
Q: Scanning a vector of int (like finding the average or max). Forward iteration vs backward iteration, which one could be faster, considering all possible compiler optimizations.
%%A: forward. Memory read into cpu cache will be in chunks i.e. cachelines, not one element at a time. Easy for forward iteration. Not sure about backward.
Q: Which one could be fastest:
void f(double arg){…..}
void f(double & arg){….}
%%A: inlining for first but not 2nd?
A: See http://stackoverflow.com/questions/722257/should-i-take-arguments-to-inline-functions-by-reference-or-value esp. the long answer.
Q: Thr1 and Thr2 on 2 CPU’s both update an object s, having 2 fields. Thr1 only updates s.field1. Thr2 only updates s.field2. No interference. No synchronization required. We observe the performance is slower than using one thread to update both fields. Any explanation?
%%A: caching in cpu
Q: weak_ptr justification, when we have shared_ptr already? I feel [[effModernC++]] has a good chapter on it.
Ashish pointed out in some apps, you could identify a clear risk of circular dependency. Replace with weak_ptr to permit the destruction.
Q: given an 2D array arr[10][5], how do you use pointer arithmetic to hit arr[1][5]
A: Contiguous. see http://stackoverflow.com/questions/7784758/c-c-multidimensional-array-internals. Note this is different from an array of pointers.
Q: what would you see if a TCP socket server has a full queue
%%A: TCP requires handshake, so if server is unable to accept a request the client would know it. Exact details are not important to me.
%%A: connection refused?
Q: what STL algorithms did you use?
%%A: foreach(), find(), copy_if(), transform(), reverse(), sort(), replace_if, remov_if