7 Replies Latest reply on Feb 4, 2014 2:07 PM by userc_42380

    Running out of program memory?

       How can I tell if I'm running out of memory during program operation?  I have a fairly simple program, but it has some very large int32 arrays (500+ elements).  On compile there's no problems, and reports as to having lots of space left...


      Flash used: 15072 of 32768 bytes (46.0 %).
      SRAM used: 1556 of 4096 bytes (38.0 %).




      But when I'm running the program it starts running horribly slow, or incorrectly.  If I reduce the size of the arrays things start working properly, but I really can't seem to narrow down where the problem is.  


        • 1. Re: Running out of program memory?

           Do I have to check for stack overflows?  

          • 2. Re: Running out of program memory?

            In C functions with array parameters are passed by pointer, not


            value, so there is no stack push of the array.




            You might consider poisting your project archive for forum to look at -










            “Create Workspace Bundle”




            Regards, Dana.

            • 3. Re: Running out of program memory?

              Stack is put aside at system start, the amount is defined in "System"-tab of the cydwr view defaulted to 0x0400 bytes which is fairly enough. Memory is usually not allocated at run-time except when you are using malloc() yourself. So when the compilation reports that everything fitted (no error-message abot ram overflow) and your stack is still 1k all will be ok.




              Happy coding



              • 4. Re: Running out of program memory?

                "Horribly slow start" of the program can be caused by the debugger when complicated breakpoints are to be executed or large amount of watched variables have to be displayed.





                • 5. Re: Running out of program memory?

                  'slow program' can also mean you have a problem in your algorithm. And if thats the case, then maybe it has some other bugs too.


                  Do you allocate your arrays statically, or via malloc()? Do you use heavy recursion / function calls?

                  • 6. Re: Running out of program memory?

                     Ugg. Why does the forum not email notifications of replies. :/  My main problem (and I have to re-read the replies) was that I was declaring the arrays in the Main() function and that it wasn't checking the memory used. Once I put the arrays outside, then it became part of the memory check and I saw I was way over.   I was able to go down to a uint16 instead of 32 and squeeze it it.  Let me check the other replies now.

                    • 7. Re: Running out of program memory?

                       No recursion. Nothing to complicated.  Arrays are statically declared.   No debugging.  Although debugging is slow when I do it, but that's always the case.  

                      It just seems like when I had the arrays declared in the main function and they weren't being included in the memory check, then I would use them, and when I accessed a portion of the memory that would have perhaps gone into the stack or whatever would have happened when the memory ran out, then the whole thing ground to a halt.  I have a simple portion that turns on a PIN, delays for 20ms, and then turns off the pin, but it would delay for 5-6 seconds...

                      But all is good now.