optimize memory usage when calling a large number of functions
Hello, I am writing a program that stores a large number of objects in the memory (thousands of), and then calls a "play" method from each one. As it goes playing, RAM usage increases drastically and a weird lag/clicking happens. Is there a possible method to clear memory (perhaps by discarding objects already played) while the script is in execution? Is there any alternative when calling a large number of functions over short periods of time? For the sake of example, take this lame pseudocode: class Foo { int fooX; float fooY; int fooZ; string fooBla; string fooBlu; fun void set(int x, float y, int z, string bla, string blu) { x => fooX; y => fooY; z => fooZ; bla => fooBla; blu => fooBlu; } fun void play() { SinOsc s => Gain g => dac; if ( x > 2 ) { fooY * x => s.freq; } else { if ( z < 4 ) { fooY * z => s.freq; } else { fooY => s.freq; } } 0.5 => g.gain; if ( bla == "fast" ) { 10::ms => now; } else { if ( bla == "slow" ) { 500::ms => now; } else { 200::ms => now; } } } (now imagine a function that sets thousands of Foo objects, stores them into an array and afterwards iterate through said array, calling .play() function for each item. at this point things become *very* slow because of too many objects filling up the memory). Even using --silent, the script is eventually sluggish because memory still is filled up. I hope you can point me to the right direction! -- Jean Menezes da Rocha Compositor Professor -- Faculdades Est Mestre e Doutorando em Composição pela Universidade Federal da Bahia
On Thu, Oct 15, 2015 at 6:57 PM, Jean Menezes da Rocha < jean@menezesdarocha.info> wrote:
Hello,
I am writing a program that stores a large number of objects in the memory (thousands of), and then calls a "play" method from each one. As it goes playing, RAM usage increases drastically and a weird lag/clicking happens. Is there a possible method to clear memory (perhaps by discarding objects already played) while the script is in execution? Is there any alternative when calling a large number of functions over short periods of time?
For the sake of example, take this lame pseudocode:
class Foo {
int fooX;
float fooY;
int fooZ;
string fooBla; string fooBlu;
fun void set(int x, float y, int z, string bla, string blu) {
x => fooX;
y => fooY;
z => fooZ;
bla => fooBla;
blu => fooBlu;
}
fun void play() {
SinOsc s => Gain g => dac;
if ( x > 2 ) { fooY * x => s.freq; }
else { if ( z < 4 ) { fooY * z => s.freq; } else { fooY => s.freq; } }
0.5 => g.gain;
if ( bla == "fast" ) { 10::ms => now; } else { if ( bla == "slow" ) { 500::ms => now; } else { 200::ms => now; }
You may want to try unchucking from the dac here s =< g; g =< dac; See http://chuck.cs.princeton.edu/doc/language/ugen.html#connect I haven't seen memory usage slow ChucK down, but connecting too many things to dac sometimes does.
}
}
(now imagine a function that sets thousands of Foo objects, stores them into an array and afterwards iterate through said array, calling .play() function for each item. at this point things become *very* slow because of too many objects filling up the memory).
Even using --silent, the script is eventually sluggish because memory still is filled up.
I hope you can point me to the right direction! -- Jean Menezes da Rocha Compositor Professor -- Faculdades Est Mestre e Doutorando em Composição pela Universidade Federal da Bahia
Hope this helps! michael
I am sorry that my example did not make justice to my actual code... I
already do unchuck everything after using them. But you have pointed me to
something interesting, anyway: many of my objects (but not all of them)
have an Envelope chucked to a Pan2, which is permanently chucked to dac. I
only manage to unchuck my waveforms and/or stk instruments from the
Envelope (which is reused everytime). I am gonna try and do things a little
differently and then I can give you a more accurate heads up on this
subject.
Thanks for your support!
Em 16/10/2015 13:18, "Michael Heuer"
On Thu, Oct 15, 2015 at 6:57 PM, Jean Menezes da Rocha < jean@menezesdarocha.info> wrote:
Hello,
I am writing a program that stores a large number of objects in the memory (thousands of), and then calls a "play" method from each one. As it goes playing, RAM usage increases drastically and a weird lag/clicking happens. Is there a possible method to clear memory (perhaps by discarding objects already played) while the script is in execution? Is there any alternative when calling a large number of functions over short periods of time?
For the sake of example, take this lame pseudocode:
class Foo {
int fooX;
float fooY;
int fooZ;
string fooBla; string fooBlu;
fun void set(int x, float y, int z, string bla, string blu) {
x => fooX;
y => fooY;
z => fooZ;
bla => fooBla;
blu => fooBlu;
}
fun void play() {
SinOsc s => Gain g => dac;
if ( x > 2 ) { fooY * x => s.freq; }
else { if ( z < 4 ) { fooY * z => s.freq; } else { fooY => s.freq; } }
0.5 => g.gain;
if ( bla == "fast" ) { 10::ms => now; } else { if ( bla == "slow" ) { 500::ms => now; } else { 200::ms => now; }
You may want to try unchucking from the dac here
s =< g; g =< dac;
See
http://chuck.cs.princeton.edu/doc/language/ugen.html#connect
I haven't seen memory usage slow ChucK down, but connecting too many things to dac sometimes does.
}
}
(now imagine a function that sets thousands of Foo objects, stores them into an array and afterwards iterate through said array, calling .play() function for each item. at this point things become *very* slow because of too many objects filling up the memory).
Even using --silent, the script is eventually sluggish because memory still is filled up.
I hope you can point me to the right direction! -- Jean Menezes da Rocha Compositor Professor -- Faculdades Est Mestre e Doutorando em Composição pela Universidade Federal da Bahia
Hope this helps!
michael
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (2)
-
Jean Menezes da Rocha
-
Michael Heuer