GLBasic forum

Main forum => GLBasic - en => Topic started by: ampos on 2011-Oct-31

Title: Memory use and local variables
Post by: ampos on 2011-Oct-31
On my new app, I have this function:

function bla:
   local pix[],tpix[]

   dim pix[4000*3000] //number can vary
   dim tpix[1000*700]

   code...
endfunction

And this function is called every 10 seconds, during HOURS, so it is called a ton of times.

Could it drive to problems?


My app, the photoframe, has been working without problems for several hours, but lately it is having problems.

First it was using loadsprite (0 or 1) to load photos, and I think it was also with 3.0.4. Working fine.

But from a week or so, I found the touchpad with the following msg: "the app photoframe has closed unexpectly" (or something similar). The loadmemsprite function was not implemented.

Amazing, yesterday I found the TP running with Android, what means that the whole unit was reseted, as Android is the default OS when powered on.

Currently I have added a log file, to try to find if there is an error or it was just simply a malformed jpg file.

Is glb_on_quit called when the app closes due a internal error? Is there a way to know the error that closed the app?
Title: Re: Memory use and local variables
Post by: Ruidesco on 2011-Oct-31
I don't know if this will make any difference, but maybe doing a "DIM pix[0]; DIM tpix[0]" at the end of the function could work.
Title: Re: Memory use and local variables
Post by: Kitty Hello on 2011-Oct-31
It's a local object. Memory will be freed when it goes out of scope (on return).
Title: Re: Memory use and local variables
Post by: ampos on 2011-Oct-31
What I was asking is if memory will be fragmented because so many local create-destroy, and if there is a better way to improve memory handling by this routine.

Is glb_on_quit called when the app closes due a internal error? Is there a way to know the error that closed the app?
Title: Re: Memory use and local variables
Post by: Kitty Hello on 2011-Oct-31
No, when the memory does not get allocated, you're pretty stuck with a program crash.
Title: Re: Memory use and local variables
Post by: MrTAToad on 2011-Oct-31
If you are using large arrays then they should be allocated only once at the start of the program.  In addition, don't forget that a defined array size would be a lot more than 4 or 8 bytes, as it is a C++ class...

If you want just floats/integers, it might be a good idea to use malloc/new - that way you could save a bit of memory...