Assuming many consecutive calls of foo
in the below correctly-functioning class. Also, my code need not be thread-safe but small memory-footprint is critical.
class A{
public:
void foo(){
double x[10000];
// ...
}
};
Question: (How) Should I change the implementation of x
to improve performance?
Ideas:
- I could leave it as is because freeing the space of
x
might be beneficial to keep the whole stack in cache at every time, e.g., when other functions (bar) also use an internal buffer of considerable size. - I could make it a private class attribute but then its reserved memory could not be used by B::bar.
- If I assume that cache is no issue and if I assume I do not want to litter my class attribute list with internal function buffers, I might want to use
static double x[10000];
?