It is assumed that for some reason you are allowed to use static memory in a C program. I have a basic structure that I use in several places defined below:
#define SMALL_STUFF_MAX_SIZE 64 typedef struct { ... double data[SMALL_STUFF_MAX_SIZE]; } SmallStuff;
Now I was asked to add a new function that will lead to a specific case when I need the same structure, but with a much larger array. I cannot afford to grow the SmallStuff structure array, because the memory is too tight. Therefore, I made a special version of the structure described below, which I eventually contributed to (SmallStuff *) when calling functions that expect a pointer to the SmallStuff structure (the actual size of the "data" is properly processed in these functions)
#define BIG_STUFF_MAX_SIZE 1000000 typedef struct { ... double data[BIG_STUFF_MAX_SIZE]; } BigStuff;
Obviously, the correct way to do this would be to dynamically allocate memory, but as said above, I cannot use dynamic memory allocation.
Are there any side effects that I should consider? Or more effective ways to solve this problem?
Thanks in advance.
source share