I'm looking for guidance on what this problem might be referred to, or algorithms or approaches to solve it.
I have functions that are defined at compile time. During run-time, the user selects a number of functions to be called in a chain. Later on in the program, I have performance critical sections where the chain will be called many times.
It's kind of like the concept of a Calculator app, where you would know the operators and maybe even more complex functions, but its only at run-time that the user defines the order of operations to call and provides numbers for input, except performance really matters when they hit "calculate".
The best solution I can think of is a list-like collection where each element holds a function pointer to call, and holds a series of references/pointers to the necessary inputs and outputs.
I feel like this is a problem other programmers have encountered before though, so I'm wondering if it has a name or if there are any other resources I should know about.
I'm writing the program in C++, but I feel this is a general programming problem.
Thanks!
The approach you've outlined is actually reasonable, but you might not be thinking about it in a what that would produce the best implementation in practice.
The problem -- user arranges operations the describe a process which you must then execute many times -- is essentially the same problem as implementing a programming language, although probably simpler.
The possible solutions run from strict interpretation, where execute the process by interpreting its definition every time, to strict compilation, where you compile the process into natively executable machine code and then just run that.
You likely want something in between, where you compile the process description into an object that implements an appropriate execute
method, and you want it to be as fast as possible.
You are on this path already so, as I said, I think you are taking a reasonable approach, BUT it's not a good idea to try to invent a single kind of node or building block from which the whole process is built. Use different implementations for different kinds of structures so that you don't have to evaluate a whole bunch of "if it's this kind of operation then do it this way" logic during execution.