Let me try to outline the problem a little more.
- You have a surface on which you can draw dots and lines, and you know how to make it look the way you want it to look.
- You have a data source that provides points for drawing and that the data source changes on the fly.
- You want the surface to accurately reflect the incoming data as close as possible.
The first question is, how about your situation slowly? Do you know where your delays come from? First, make sure you have a problem to solve; secondly, make sure you know where your problem comes from.
Let's say your problem is with the size of the data, as you mean. How to solve this is a difficult question. It depends on the properties of the graphic data - which invariants you can accept and so on. You talked about storing data in float[] , so I'm going to assume that you have a fixed number of data points that change in value. I’m also going to suggest that for 100 or 1000 what you had in mind was “many and many,” because frankly 1000 floats are just not a lot of data.
When you have a really large drawing array, your performance limit will ultimately come from looping through the array. Then your performance improvement will reduce the number of elements that you loop. This is where data properties come into play.
One way to reduce the scope of the redraw operation is to maintain a dirty list that acts like a Queue<Int> . Each time a cell in your array changes, you queue that array index, marking it as dirty. Each time the drawing method goes back, it deletes a fixed number of entries in the dirty list and only updates a piece of your displayed image corresponding to these entries - you will probably have to scale a little and / or smooth or something, because with so many data points you probably got more data than screen pixels. the number of records that you redraw in any given frame update should be limited by the required frame rate - you can do this adaptive, based on the metric of how long the previous draw operations were performed and how deep this dirty list is, to maintain a good balance between frame rate and time of visible data.
This is especially convenient if you are trying to simultaneously draw all the data on the screen. If you are viewing only a piece of data (for example, in a scrollable form), and there is some kind of correspondence between the positions of the array and the window size, then you can “finish” the data - in each callback, only the subset of data that is actually on the screen is taken into account. If you also have a “scale,” you can mix the two methods — this can get complicated.
If your data is terminated in such a way that the value in each element of the array determines whether the data point is on or off, consider using a sorted list of pairs, where the sort key is the value. This will allow you to perform the window optimization described above in this situation. If windowing occurs in both dimensions, you will most likely only need to perform this or that optimization, but there are two range query structures that can also give you this.
Let's say my assumption about a fixed amount of data was wrong; instead, you add data to the end of the list, but existing data points do not change. In this case, you are probably better off with a related structure like Queue that discards old data points rather than an array, because increasing your array will tend to stutter the application unnecessarily.
In this case, your optimization consists of preliminary drawing into the buffer following your turn - since new elements enter the queue, shift the entire buffer to the left and draw only the area containing the new elements.
If this is / rate / data input, that is the problem, then use the structure in the queue and skip the elements - either collapse them as they are added to the queue, save / draw each element n th, or something similar.
If instead, the rendering process, which takes all your time, considers rendering in the background stream and saving the rendered image. This will allow you to take as much time as you want to redraw - the frame rate inside the diagram itself will drop, but not your overall application reaction.