Skip to main content
9 events
when toggle format what by license comment
Nov 19, 2015 at 3:03 comment added Barry @BlueRaja I said the main problem about the operator, not the main problem of the whole class.
Nov 19, 2015 at 0:44 comment added BlueRaja - Danny Pflughoeft A branch is the "main thing" that kills performance!? A successfully-predicted branch is practically free, while even a failed branch prediction (which will be rare in this case) is still faster than a single integer division. And all of these things are orders of magnitude faster than a single allocation. The real performance-killer here was the excess allocations in push_back(). I wrote a blog post relating to timings here.
Nov 18, 2015 at 20:33 comment added Deduplicator Do you really need dynamically resizable vectors, or would a far simpler and more efficient std::array suffice?
Nov 18, 2015 at 20:30 comment added Matteo Italia Last time I had to implement a similar thing (think std::valarray for operators but std::array for the rest) the branch itself in the operator[] was mostly irrelevant since it's predicted extremely well by the branch predictor (the check always fails) and the compiler put the exception-throwing code out of the hot path. The real problem was that the exception-creation code was big enough to prevent the function from being inlined, so it was the function call overhead to kill performance. Separating the throw in a function may give the bounds checking at extremely reduced cost.
Nov 18, 2015 at 18:37 vote accept Jaime Machado
Nov 18, 2015 at 16:58 comment added Jaime Machado 23milion, I´m using this code to process large 3D files.
Nov 18, 2015 at 16:44 comment added Barry @JaimeMachado 2.3 million vectors?!?
Nov 18, 2015 at 16:37 comment added Jaime Machado First of all thanks Barry for your help. Regarding the size im going to use unsigned char which will save me 14bytes since im allocating 23000000 vectors thats alot of memory. Regarding the memory allocation. i´m not using new to alocate memory . Im actually using std::realloc the line new (pDest)DataType(*pOrig); does not allocates memory, thats why i use free.
Nov 18, 2015 at 16:33 history answered Barry CC BY-SA 3.0