Running out of program memory?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 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.  

Thoughts?

0 Likes
7 Replies
Anonymous
Not applicable

 Do I have to check for stack overflows?  
http://www.cypress.com/?app=forum&id=2233&rID=70925

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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 -

   

 

   

    

   

          

   

“File”

   

“Create Workspace Bundle”

   

  

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

"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.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

'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?

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

 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.

0 Likes