Author |
Message |
RobinFencott
Joined: Jul 26, 2007 Posts: 4 Location: London
|
Posted: Thu Jul 26, 2007 9:00 am Post subject:
Help with sporking and memory usage. |
|
|
Hello.
When I spork a function, it seems not to free its memory, once the spork has finished. I'm monitoring the memory usage in the task manager, and it just spirals up and up, taking up around 800k with each new sporking.
I'm using the latest chuck version, on windows xp home.
This seems to apply to functions that include their own ugens. Is this simply a fact of life, or am I doing something stupid and inefficient in my code?
I tried using the unchuck =< at the end of the function, and also using me.exit(), but these make no difference.
I've attached a file to show you what I mean.
I'm intending to use chuck in a club environment, and want to make a program that will run for over an hour. If I use sporked functions in this way, I calculate my computer will run out of memory in a little under 17 minutes, so can anyone help me out?
kind regards.
Robin.
Description: |
|
Download |
Filename: |
teddyspork2.ck |
Filesize: |
1.26 KB |
Downloaded: |
430 Time(s) |
|
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Jul 26, 2007 9:18 am Post subject:
|
|
|
You are right; garbage collection doesn't work yet. This is high on the wishlist.
In the meantime; very often there are ways around the problem, for example using Event signalling, using Events you can keep your shreds around and re-use them, meaning they'll never have to exit and so they'll never have to restart.
I don't have the time right now but later tonight today I could help you re-write your example to take advantage of events. _________________ Kassen |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Jul 26, 2007 9:18 am Post subject:
|
|
|
Oh, and welcome on board! _________________ Kassen |
|
Back to top
|
|
|
RobinFencott
Joined: Jul 26, 2007 Posts: 4 Location: London
|
Posted: Thu Jul 26, 2007 9:37 am Post subject:
|
|
|
Ah, ok, fair enough.
I'll have a look at the events section of the manual...
I was already thinking about ways of sporking a single shread, and then getting it to wait for new events...but if you could give me a quick example, that would be fantastic.
I really love Chuck, and it's great to have such a supporting forum to be a part of.
Kind regards.
Robin |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Jul 26, 2007 10:00 am Post subject:
|
|
|
Oh, there I am again. Had to do groceries as I was out of coffee. I'm sure you understand :¬).
I had a quick glance at your code and it seems to me that you are sporking a function every five seconds which takes 6.75 seconds to run. Hence, due to the 1.75 seconds that they overlap you'll need two of those running in paralel.
Let's asume you make a event called "sperk" as we are replacing a spork with a event.
Now your function would look something like this;
---------------------------------------------
fun void teddy voice()
{
//defining ugens goes here
//I'd also define all my variables here
while(true)
{
//wait for the event, make sure to signal it, not broadcast, in your main shred
sperk => now;
//adjust some settings here
some_time => now;
//modulate some more settings
more_time => now;
//at this point your function will have done it's stuff, now it will go back to the beginning of the loop and wait for the next signaled "sperk" event
}
}
spork ~ teddy voice();
spork ~ teddy voice();
-------------------------------------
You could still unchuck all ugens from the dac when not used but that will only save you cpu, not memory.
Most of the time it's totally possible to write ChucK code that uses tricks like this to get around garbage. Signalling events if very usefull for that and here we only need to use them in their most simple form so if you look that up and restructure your code like I did above (you can re-use nearly all of what you wrote) you should be in business. _________________ Kassen |
|
Back to top
|
|
|
RobinFencott
Joined: Jul 26, 2007 Posts: 4 Location: London
|
Posted: Thu Jul 26, 2007 10:39 am Post subject:
|
|
|
Hey Kassen, that's great, thanks a lot.
I got it working straight away, after filling out your example.
This is a very neat way to do things...and saves doing comparisons to now etc, to schedule events...good stuff!
...and I know exactly what your talking about..it's all about the coffee these days.
cheers.
Robin |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Jul 26, 2007 10:41 am Post subject:
|
|
|
Excelent. Let us know how your gig goes. _________________ Kassen |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Sat Jul 28, 2007 10:54 am Post subject:
|
|
|
Oh! This is such a great guideline for doing this in ChucK.
I'm planning to practice this issule in chuck today,
and happy to see this thread and it also inspires me lots.
I'd like to implement this with OSC also to extend to some more flexible use.
Maybe, I'll try to design some sound module in my style with basic oscillators and wiring but with some crazy tweaking functions..
^_^" |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sun Jul 29, 2007 7:06 am Post subject:
|
|
|
Yeah, aside from voice-stealing event signalling can very easily give you a equivalent of voice management in traditional synths. I like it :¬) _________________ Kassen |
|
Back to top
|
|
|
|