[chuck-users] optimize memory usage when calling a large number of functions

Michael Heuer heuermh at gmail.com
Fri Oct 16 12:05:20 EDT 2015


On Thu, Oct 15, 2015 at 6:57 PM, Jean Menezes da Rocha <
jean at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151016/8c3348a9/attachment.html>


More information about the chuck-users mailing list