Framerate decrease by using an Array in a Thread
in
Programming Questions
•
2 months ago
Dear processing-community,
maybe someone can answer me a funny question. For some greater reason I am using forcefields to move objects over a field. as these objects cause these fields themselves, and the pixels of the field only communicate with their direct neighbors, I am also using a seperated thread to calculate these fields. The thread runs about 15times faster than the draw(), which improves the speed and quality of the field. The thread stores its calculated values in Arrays. The weird thing is: if I pass these values from thread to draw() the framrate goes down from 60 to 35. It does not matter if if pass 1 Array or 8. It does not matter, if I pause the thread, while the draw() is reading the values, nor if I make the thread writing the values into a static class, that works as a buffer, so that the draw can read them whenever it gets to it. It doesn't even matter if I set a flag, that the thread only writes the values once, after the draw() read them.
No change in Calculation, the difference between the commented and the uncommented part of the cited method taken from the thread is the one stated above:
void write() {
for (int i=0; i<resQ; i++) {
buffy.disp[i] = disp[i];
buffy.wall[i] = wall[i];
buffy.r[i] = rOne[i];
buffy.g[i] = gOne[i];
buffy.b[i] = bOne[i];
buffy.inEx[i] = iOne[i];
buffy.fuEm[i] = fOne[i];
buffy.inSh[i] = iOne[i];
buffy.coRe[i] = cOne[i];
buffy.trPe[i] = tOne[i];
// buffy.disp[i] = 20;
// buffy.wall[i] = 10;
//
// buffy.r[i] = .5;
// buffy.g[i] = .5;
// buffy.b[i] = .5;
//
// buffy.inEx[i] = 5;
// buffy.fuEm[i] = 5;
// buffy.inSh[i] = 5;
// buffy.coRe[i] = 5;
// buffy.trPe[i] = 5;
write = false;
}
}
I can live withe a framerate about 30, no doubt. but as the thread has to access its Arrays anyway during calculation and the Buffer-class has to acces its Arrays anyway during passing the values to the field-objekt class - I do not understand why particularly THIS connection is causing a loss of performance. If anyone has got an idea... I'd like to know!
regards
maybe someone can answer me a funny question. For some greater reason I am using forcefields to move objects over a field. as these objects cause these fields themselves, and the pixels of the field only communicate with their direct neighbors, I am also using a seperated thread to calculate these fields. The thread runs about 15times faster than the draw(), which improves the speed and quality of the field. The thread stores its calculated values in Arrays. The weird thing is: if I pass these values from thread to draw() the framrate goes down from 60 to 35. It does not matter if if pass 1 Array or 8. It does not matter, if I pause the thread, while the draw() is reading the values, nor if I make the thread writing the values into a static class, that works as a buffer, so that the draw can read them whenever it gets to it. It doesn't even matter if I set a flag, that the thread only writes the values once, after the draw() read them.
No change in Calculation, the difference between the commented and the uncommented part of the cited method taken from the thread is the one stated above:
void write() {
for (int i=0; i<resQ; i++) {
buffy.disp[i] = disp[i];
buffy.wall[i] = wall[i];
buffy.r[i] = rOne[i];
buffy.g[i] = gOne[i];
buffy.b[i] = bOne[i];
buffy.inEx[i] = iOne[i];
buffy.fuEm[i] = fOne[i];
buffy.inSh[i] = iOne[i];
buffy.coRe[i] = cOne[i];
buffy.trPe[i] = tOne[i];
// buffy.disp[i] = 20;
// buffy.wall[i] = 10;
//
// buffy.r[i] = .5;
// buffy.g[i] = .5;
// buffy.b[i] = .5;
//
// buffy.inEx[i] = 5;
// buffy.fuEm[i] = 5;
// buffy.inSh[i] = 5;
// buffy.coRe[i] = 5;
// buffy.trPe[i] = 5;
write = false;
}
}
I can live withe a framerate about 30, no doubt. but as the thread has to access its Arrays anyway during calculation and the Buffer-class has to acces its Arrays anyway during passing the values to the field-objekt class - I do not understand why particularly THIS connection is causing a loss of performance. If anyone has got an idea... I'd like to know!
regards
1