3 ms·
The context is missing, what's allowed and what's not. If it's allowed to make own classes, the best thing it can be done is to introduce MyNumber abstract cla
by acqq 10y ago
The context is missing, what's allowed and what's not.
If it's allowed to make own classes, the best thing it can be done is to introduce MyNumber abstract class, then inherit it to make MyDouble, then make NumberFactory and access every double through the virtual operators. Then let every temporary variable be created (with the new operator!) on every loop pass, of course using the factories. Define the operations in a way to need the new temporary MyNumbers too. That way the creations would be hidden in the classes, the calculation would still look relatively innocent.
And additionally, make classes so that they have to do runtime casts for every operation. Make the classes to have multiple inheritance, to make sure figuring out in the runtime which cast works as nontrivial as possible.
I know one commercial program where the programmers actually implemented all this, even more convoluted, and even believed that they "improved" the code with all these insanities.
For style points, use all possible boost classes that you can to achieve the above behavior.
- mlvljr 10y agoAlso, have a placement new in place, to scatter allocations afround the memory space :)
- colejohnson66 10y agoBut would that cause cache fails? Wouldn't that just increase the time needed to access data?
- acqq 10y agoFor really nice cache misses the arrays (explicit or implicit) are needed. Havng the allocations of the objects for calculations gives us chance for that too: we'd also need the different, crossed lifetimes of allocated objects, which can be done with "smart" pointers (the application I've mentioned used these too! That's why I've mentioned Boost).
- dottrap 10y agoSeems like virtual functions leave you more vulnerable to instruction cache misses. Large enough blocks of code combined with bad branch prediction can leave you all sorts of bad performance here.
- dottrap 10y agoYour case seems to fit nicely with "Typical C++ Bullshit" by Mike Acton (and any of his Data Oriented Design talks). https://macton.smugmug.com/Other/2008-07-15-by-Eye-Fi/n-xmKDH/i-5D2mGTn https://macton.smugmug.com/Other/2008-07-15-by-Eye-Fi/n-xmKD...