Forums > Dev

Calling jbox_redraw from perform routine

Mar 30 2011 | 10:50 am


I’m making an audio UI object. Currently I’m calling the jbox_redraw routine from inside the perform routine. This seems to work fine, but I’m wondering if this is the best way to do this or not… My timing between draws is governed by an sample counting mechanism that happens to be necessary for my task anyway.

I will probably a data lightweight thread mechanism around the data I’m changing form the perform routine to prevent it being altered whilst drawing is taking place. Apart from this issue, is there anything else I should take into account? I see that pictmeter~ calls the draw routine from a clock – is this particularly better performance wise?

Any thoughts appreciated.



Mar 30 2011 | 10:59 am

Hi Alex.

When you call jbox_redraw(), you don’t trigger an immediate redraw – in fact, you just ask for the paint method to be called in the main thread, at an unspecified time in the future. For this reason, calling it from a clock is a better idea. And at the same time you should not make assumptions about a very precise state your object should be in when the paint method is actually called – if this is the case, you should cache the relevant data, to be used by paint when it needs to.


Mar 30 2011 | 11:22 am

Hi Andrea,

Yes – I understand that about the redraw not being immediate. However, that doesn’t explain why a clock is better. I assume the draw is serviced as soon as possible wherever it is called from, so in fact using a sample counter would be more likely to get the redraw closer to the data update (my data updates on a specific sample) than having a clock check the sample counter which just adds an unnecessary layer in between.

My question is if this is safe (it seems to be) or not advisable for reasons of performance.



Mar 30 2011 | 12:28 pm

I see what you mean. I guess the point is that setting a clock is cheaper than calling jbox_redraw – this might as well have to do with different locking mechanisms used in the two operations. If, for example, jbox_redraw locks the global critical region, calling it from the perform method would be very unadvisable… of course I’m just guessing.

On the other hand, I don’t think that the delay introduced by a clock_delay of 0 ms is significant, compared with the delay between a jbox_redraw call and the execution of the paint method.


Viewing 4 posts - 1 through 4 (of 4 total)

Forums > Dev