We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › erratic  cpu ussage
Page Index Toggle Pages: 1
erratic  cpu ussage (Read 938 times)
erratic  cpu ussage
Jun 18th, 2005, 5:29am
 
dont know if anyone else experiences this on their computers. Some sketches that I open will start running smoothly and then slowly the cpu ussage will escalate. I wrote a sketch were this happens. the sketch will start out smoothly and over a couple of minutes the cpu ussage will climb and the performance will drop, then it will drop back down and run smooth again for a couple of seconds then back up. the sketch I wrote shouldnt be doing anything different when its running smoothly than when its stuttering. any clues why this happens and any ways to get around it

when I try it using P3D it stays at a steady stuttering speed, while OPENGL it goes from smooth to choppy. I also have framerate set to 30 to try to force it to stay steady but still nothing changes

I was wondering if anyone else could try the sketch and let me know how it runs. I have a computer with a 3.2 processor 1gb of memory 128 vid card. just swept the computer for adware,spyware, and viruses, emptied internet files, closed unnessary processes, and the hard drive is defragged. but maybe Im missing something?

this isnt the only sketch this happens to many other sketches that I write or find online exhibit this behaviour of beggingn running smoothly and a minute or so into it start to slow down.



import processing.opengl.*;
int step=20;
int limit=30;
int l=0;
building[] buildings;

void setup(){
size(800,600,OPENGL);
framerate(30);
buildings=new building[0];

builder();
fill(100,100,255);

noStroke();

}


void draw(){
background(0);
//println(buildings.length);
fill(80,80,80);
beginShape(QUADS);
vertex(-400,500,-800);
vertex(1200,500,-800);
vertex(1200,500,200);
vertex(-400,500,200);
endShape();

if(l<limit){
builder();
l++;
}

fill(100,100,250);
for(int i=0; i<buildings.length; i++){
buildings[i].update();
}
}

void builder(){

int news=int(random(5,10));
news=8;
building[] tmp=new building[buildings.length+news];
arraycopy(buildings,0,tmp,0,buildings.length);
for(int i=buildings.length; i<(buildings.length+news); i++){
tmp[i]=new building(i);
}
buildings=tmp;

}


building[] remove(building[] array, int item) {

 building outgoing[] = new building[array.length - 1];
 System.arraycopy(array, 0, outgoing, 0, (item));

 System.arraycopy(array, item+1, outgoing, (item), (array.length-item-1));
 
 return outgoing;
}  




class building{
float x,y,z;
int w,h,d,pos;

building(int poss){
pos=poss;
build();


}

void build(){
//x=random(-400,1200);
x=((pos*50)%1600)-400;
y=500;
//z=(random(-100,0))-700;
z=-700;
w=40;//int(random(10,70));
h=150;//int(random(10,150));
d=5;//int(random(10,70));
}
void update(){


pushMatrix();
translate(x,y,z);
box(w,h,d);
popMatrix();
z+=step;


if(z>100){
//for (int i=(pos+1); i<buildings.length; i++){
//buildings[i].pos-=1;
//}
//buildings=remove(buildings,pos);
build();
}
}

}

as far as this sketch goes I believe its drawing 328 box()'s on screen at once is that too much for processing to handle even in OPENGL. This sketch is mostly an experiment to see how much stuff I can get moving on screen at once to get an idea of it can handle for some future sketches im thinking of.


thanks




Re: erratic  cpu ussage
Reply #1 - Jun 18th, 2005, 6:33pm
 
the main thing that will cause this kind of behavior is using "new" inside of draw.. how often is that function being called that creates new objects and does the arraycopy and whatnot? if it's a fair amount, you'll get some stuttering because you're moving memory around a bunch, and java's garbage collector has to run and unload things.
Re: erratic  cpu ussage
Reply #2 - Jun 22nd, 2005, 5:19am
 
ok I changed the sketch so that there is no "new" calls in the draw loop, all new objects are created in "setup" but the performance in the sketch is still going from smooth to stuttering.

what could be causing this?


import processing.opengl.*;
int step=20;
int limit=30;
int l=0;
building[] buildings;

void setup(){
size(800,600,OPENGL);
framerate(30);
buildings=new building[0];

builder();
fill(100,100,255);

noStroke();

}


void draw(){
background(0);
//println(buildings.length);
fill(80,80,80);
beginShape(QUADS);
vertex(-400,500,-800);
vertex(1200,500,-800);
vertex(1200,500,200);
vertex(-400,500,200);
endShape();

if(l<limit){
//builder();
l++;
}

fill(100,100,250);
for(int i=0; i<buildings.length; i++){
buildings[i].update();
}
}

void builder(){

//int news=int(random(5,10));
int news=300;
building[] tmp=new building[buildings.length+news];
arraycopy(buildings,0,tmp,0,buildings.length);
for(int i=buildings.length; i<(buildings.length+news); i++){
tmp[i]=new building(i);
}
buildings=tmp;

}


building[] remove(building[] array, int item) {

 building outgoing[] = new building[array.length - 1];
 System.arraycopy(array, 0, outgoing, 0, (item));

 System.arraycopy(array, item+1, outgoing, (item), (array.length-item-1));
 
 return outgoing;
}  




class building{
float x,y,z;
int w,h,d,pos;

building(int poss){
pos=poss;
build();


}

void build(){
//x=random(-400,1200);
x=((pos*50)%1600)-400;
y=500;
//z=(random(-100,0))-700;
z=-700-((pos%10)*30);
w=40;//int(random(10,70));
h=150;//int(random(10,150));
d=5;//int(random(10,70));
}
void update(){


pushMatrix();
translate(x,y,z);
box(w,h,d);
popMatrix();
z+=step;


if(z>100){

build();
}
}

}
Page Index Toggle Pages: 1