Stack overflow. Too many functions called, maximum memory for variables exceeded when using array of structures
-
why would they be the same? The first is 256 * 256 structs of type terrainDescriptor which contains a float. The second is a simply array of 256 * 256 int's
-
An int would be 4 bytes, right? Maybe a little bit more per int for interpreter purposes. But, how much does space does a struct take up that contains an int?
-
Let me use the C syntax, to explain what I'd in mind:
#include <stdio.h> #define GRID_SIZE 256 typedef struct { float alt; } terrainDescriptor; terrainDescriptor firstTerrain[GRID_SIZE][GRID_SIZE]; float secondTerrain[GRID_SIZE][GRID_SIZE]; int main(void) { printf("sizeof(first)=%lu\n", sizeof(firstTerrain)); printf("sizeof(second)=%lu\n", sizeof(secondTerrain)); return 0; }
This program above prints:
sizeof(first)=262144
sizeof(second)=262144Also my variables in F4NS are not declared in a function context, so they shouldn't go to stack - this is the same as in this C code snipet, those variables there are also not sitting on stack. (I know F4NS is an interpreter so no bss section, but heap might be more appropriate in this case)
-
FUZE is dynamically typed, not statically typed like C, so every value has to contain extra information about its type.
-
@12Me21 Correct!
-
@12Me21 I think it'd be interesting to see the actual sizeof(terrainDescriptor) in F4NS. Since in the code above I was more strict in the struct declaration - I made it a float declared - and still it eats more memory than the more dynamic one with the array.
-
@mixaal We are already aware of the stack overflow bug. I know that it is being worked on and is already considerably improved.
Beyond that, you're clearly a very advanced user and I doubt I'm going to be able to give you an answer at a technical level that you are going to be happy with because I don't know the code to that level, so I'm not going to speculate at this time.
Thanks for reporting the issue though, as I said, I know it's already being worked on. we'll let you know should we find there is a workaround you can use until a fix is released.
-
Thanks for the info @Martin!
-
I know the stack overflow issue looked into by the FUZE team, but here's some code that doesn't make sense. In the example, all data should be global and no functions are called. Nevertheless, the message about too many functions and a filled data stack is shown. Perhaps this is already covered by the upcoming fixes, but just to be sure...
Here's the code (sorting 1000 integers that are located in a struct array):
struct mystruct int val = 1 endstruct ARRAY_SIZE = 1000 mystrust test[ARRAY_SIZE] // All data should be global mystrust v = [ .val = 1] int i = 0 int j = 0 for i = 0 to ARRAY_SIZE loop test[i].val = random(100) repeat for i = 0 to ARRAY_SIZE - 1 loop for j = i + 1 to ARRAY_SIZE loop if test[i].val > test[j].val then // Swap v = test[i] test[i] = test[j] test[j] = v endif repeat repeat for i = 0 to ARRAY_SIZE loop print(test[i].val, " ") repeat loop update() repeat
-
Maybe the error is an either/or scenario, since the stack could be used for functions and variables (gotta save the position and whatnot of where code was before entering a function)