4 ms·
We are implementing a numerical library. The problem is with temporary buffers when you are chaining functions. Array C = Array.Add(A, Array.sin(B)) The o
by pavanky 11y ago
We are implementing a numerical library. The problem is with temporary buffers when you are chaining functions.
Array C = Array.Add(A, Array.sin(B))
The output C and the output of Array.sin(B) have not been allocated from the object pool.
- sievebrain 11y agoWell for constructs like that, it's what escape analysis is meant to be good at, as those functions would be small and inlineable.
- elcritch 11y agoThis is quite difficult and puts you more into the realm of DSL's. Have you tried adding a fluent Builder interface? It's one of the better ways to handle these types of problems in Java. For example: ``` ArrBuilder = arrs; arrs.add(A, arrs.sin(B)); Array C = arrs.get(); ``` Otherwise if you're willing to do Lombok style AST manipulation you could of course do most anything you wanted, perhaps even proper operator overloading: ``` @Arrays public void test() { Array C = A + sin(B); } ``` (Just be ready for the Java programmers to rebel on you and your "dark arts" ;) )