Omnimaga
Calculator Community => TI Calculators => Calculator C => Topic started by: Torio on August 30, 2012, 02:21:03 pm
-
Hello,
Another question for you Lionel ! (...or for anybody who knows the answer of course)
This instruction throws a memory error :
void *buffer = malloc(LCD_SIZE);
I think that malloc returns only NULL when there is not enough memory, and doesn't throw any error.
Besides, I think that a lack of memory is not a problem because this code prints 3840/78868 before the malloc, so there is enough memory:
printf("%d / %lu", LCD_SIZE, HeapAvail());
I know it's vague but I can't post all the code of my fat program here, but perhaps you've encountered a situation like that before me and you could enlighten me ?
Thanks in advance,
Torio
-
Indeed, it's extremely unusual for malloc (HeapAllocPtr) to throw errors...
Browsing through the callgraphs in the documentation, I see that HeapAllocPtr calls NeedStack and HeapAllocHigh, which itself calls NeedStack and several other functions.
I'm positive that the Memory error is thrown by NeedStack - which, in turn, means that you have stored way too much data on your stack. You need to reduce your stack consumption :)
-
Well, well, well... Always that bloody stack. :banghead:
So let's review the methods you gave me in a previous subject :
eliminating SAVE_STACK (saving/restoring the screen yourself, in an allocated memory block or through the method used by the Home Screen Restore program)
Done.
reducing call nesting
I don't use recersive functions.
using the registers to pass parameters (__attribute__((__regparm__)) on single functions, -mregparm=5 compiler switch)
This may be my last option.
I don't know what you mean by passing parameters on single functions (and what is a single function, by the way ?)...
For -mregparm=5 compiler switch, I guess I have to add "-mregparm=5" at the end of the text box in Project->Options->Compilation->GCC Switches. Am I right ?
-
For -mregparm=5 compiler switch, I guess I have to add "-mregparm=5" at the end of the text box in Project->Options->Compilation->GCC Switches. Am I right ?
Yup. And that's a global switch which applies to all functions; if you wanted to enable it on several functions only, you'd use __attribute__((__regparm__(5))) in the definition of each of those functions :)
Are you saving and restoring the screen yourself to local buffers (buffers declared inside functions, as opposed to global buffers) ?
In any case, you can send me a copy of the code base, like the previous time I performed optimizations on it :)
I don't think I'll have time to do much on it before the week-end, though.
-
Are you saving and restoring the screen yourself to local buffers (buffers declared inside functions, as opposed to global buffers) ?
Yes, it's already done ;)
Yup. And that's a global switch which applies to all functions; if you wanted to enable it on several functions only, you'd use __attribute__((__regparm__(5))) in the definition of each of those functions
I applied the switch, it doesn't change anything... ???
In any case, you can send me a copy of the code base, like the previous time I performed optimizations on it
I will send it to you by mail in a few hours. ;)
I don't think I'll have time to do much on it before the week-end, though.
Oh, don't worry about that. Tomorrow is the beginning of school for me, and I take my first year of Prepa (MPSI, if you want to know) so I will only have access to my computer on holiday. You will have about 1-2 months to look my code. Is that okay ? ;D
-
Are you saving and restoring the screen yourself to local buffers (buffers declared inside functions, as opposed to global buffers) ?
Yes, it's already done ;)
But precisely, it loads the stack quite a bit ;)
I applied the switch [-mregparm=5], it doesn't change anything...
That was expected, it was unlikely to save more than, say, several dozens of bytes.
so I will only have access to my computer on holiday
But you won't have any holidays because you'll have way too much homework related to math and physics, and pretty little about computer science ;)