lua scripts and memory - LUA Scripting - CHDK Forum

lua scripts and memory

  • 11 Replies
  • 8947 Views
lua scripts and memory
« on: 11 / February / 2009, 00:23:53 »
Advertisements
i'm having odd problems with my lua libs and sunsetF16 script. the date functions aren't accessible from the log functions but i don't think i had this problem before. i'm curious if i'm running out of memory.

i'm using collectgarbage("count") which is returning values from 84 to 94. thats how much memory lua is using, i believe. is there a way to find how much memory is free?

*

Offline reyalp

  • ******
  • 14125
Re: lua scripts and memory
« Reply #1 on: 11 / February / 2009, 01:03:01 »
From  the manual
Quote
"count": returns the total memory in use by Lua (in Kbytes).
If you do collectgarbage("collect") and then log "count" again, you'll see how much of that was garbage.

You can find out how much memory camera has available by looking in misc->show memory info. Or see http://chdk.setepontos.com/index.php/topic,2831.0.html

I wouldn't expect running out of memory to make functions "inaccessible" ... but I'm not clear what you mean by that anyway. I would expect errors or crashes, depending whether it was lua or the camera that fails to allocate first.
Don't forget what the H stands for.

*

Offline fe50

  • ******
  • 3152
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: lua scripts and memory
« Reply #2 on: 11 / February / 2009, 07:18:52 »
@mattkime

What CHDK build do you use - the one from the Autobuild server ?

You can build (compile with CHDK-Shell) your own version without the features you do not need, e.g. the games - you'll have much more RAM available then...see also CHDK Wikia: Camera RAM memory usage.

Re: lua scripts and memory
« Reply #3 on: 11 / February / 2009, 07:30:08 »
>>but I'm not clear what you mean by that anyway.

A function that should be available to the program isn't. after using it several times.

Seems that the script stops for some reason every time collectgarbage("count") gets to 94.

seems to be running out of memory every 40 loops or so.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: lua scripts and memory
« Reply #4 on: 11 / February / 2009, 12:34:58 »
I very much recommend you to try my RAM OSD / lua ram free command patch if you are working witha vxworks cam (a570 if my memory serves?). Reyalp linked to it above.

I can build a build for you if you don't know how, or you can wait a few days till I finish giving it a finishing touch, giving it up for peer review and including it in trunk.

(I think I now have a low RAM warning, free RAM OSD and Lua free ram command for 48 vxworks cameras/subs working, but need to polish some edges and port it to current trunk first).

Re: lua scripts and memory
« Reply #5 on: 11 / February / 2009, 14:05:55 »
unfortunately i'm not working with a vxworks cam. i could...but i'd need to somehow bring the lessons learned back over to dryos.

my script really shouldn't consume that much memory. i suspect that modularizing may have cause some problems. perhaps it has to do with the "require" commands which are found in multiple libs? i think i need to go back and look at the memory usage of sunsetF15.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: lua scripts and memory
« Reply #6 on: 11 / February / 2009, 14:35:01 »
unfortunately i'm not working with a vxworks cam. i could...but i'd need to somehow bring the lessons learned back over to dryos.

Ok. The Lua free memory check command will actually work (partially) on dryos too, but it will use the crude brute force malloc test algorithm used in CHDK's misc menu memory info. It works (I've used it for checking things with sunsetF15) but should only be used for debugging things like this (i.e. not for logging between each timelapse shot for fun in a finished script release) because it fills up the largest available RAM block entirely before freeing it again, which could cause problems with other tasks Canon firmware may be running if I'm not mistaken.

Btw, do read that RAM page in wikia if you didn't already. To summarize what you might learn from there is that while testing this script you may want to always start it from a known steady state condition (and when using too if you indeed are short of RAM): you could start the camera to play mode, wait until camera is idle, switch to rec mode, wait until idle, shoot once, wait until idle and then start the script. Never start the script twice in a row, always power off and on in between. This all is to minimize RAM fragmentation. That one shot before starting the script is quite essential, half shoot is not enough.

Anyway, good luck...

Re: lua scripts and memory
« Reply #7 on: 11 / February / 2009, 15:25:15 »
perhaps i will switch my testing to my a590is. (or is it a 570? its been a little while...)

the idea of switching modes and taking pics on startup may present a problem. if you want to run a camera independent of human intervention, its just not possible. at that point i might have to figure out how to strip down chdk itself.

at any rate, i need to establish that this is indeed a memory problem and if so, define a solution.

*

Offline reyalp

  • ******
  • 14125
Re: lua scripts and memory
« Reply #8 on: 12 / February / 2009, 02:11:31 »
A function that should be available to the program isn't. after using it several times.
This doesn't tell me anything. Please describe the actual symptom. Is there an error message, does the camera hang, does it shut down ?
Quote
Seems that the script stops for some reason every time collectgarbage("count") gets to 94.

seems to be running out of memory every 40 loops or so.
Did you try forcing garbage collection as I suggested ?
Don't forget what the H stands for.

Re: lua scripts and memory
« Reply #9 on: 12 / February / 2009, 11:53:33 »
>>This doesn't tell me anything. Please describe the actual symptom.

It gives me an error message stating that an attempted function is nil even though it has executed the same function several times already. Apologies for my awkward description but i've never come across a problem like this in my days of programming.

yes, i am forcing garbage collection.

my next step is to strip back the functionality of my code to a rather bare bones state. i verified that sunsetF15 runs without problems. either there is something structurally wrong with my code or one of the libs is tearing things up. i'm curious if it coudl be the save table code but thats most because i don't understand it completely.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal