Some libraries offer the ability to separate setup and execution, esp if the setup portion has undesirable characteristics such as unbounded latency.
If the program needs to have this reflected in its structure, then it is natural to have:
void setupXXX(...); // which calls the setup stuff
void doXXX(...); // which calls the execute stuff
The problem with this is that the structure of setupXXX and doXXX is going to be quite similar (at least textually -- control flow will prob be more complex in doXXX).
Wondering if there are any ways to avoid this.
Example:
Let's say we're doing signal processing: filtering with a known kernel in the frequency domain.
so, setupXXX and doXXX would probably be something like...
void doFilter(FilterStuff *c) {
for (int i = 0; i < c->N; ++i) {
doFFT(c->x[i], c->fft_forward_setup, c->tmp);
doMultiplyVector(c->tmp, c->filter);
doFFT(c->tmp, c->fft_inverse_setup, c->x[i]);
}
}
void setupFilter(FilterStuff *c) {
setupFFT(..., &(c->fft_forward_setup));
// assign the kernel to c->filter
...
setupFFT(..., &(c->fft_inverse_setup));
}