Drawing lines is not memory efficient

Drawing lines (right now) is designed to take an array of points, and associate them with a line object.
If I want to draw a line which is made up of 30K points, I have to create an array of 30K points!
This consumes too much memory needlessly, and not efficient at all.

Right now, if I want to draw two lines, I have to create an array of four points.

Here is an example:

static lv_style_t style_line;
lv_style_set_line_width(&style_line, 1);
lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_line_rounded(&style_line, true);

lv_obj_t * line1;
line1 = lv_line_create(lv_scr_act());
lv_obj_add_style(line1, &style_line, 0);

// The followings will draw two lines correctly
static lv_point_t line_points[4];
line_points[0] = (lv_point_t){100,30};
line_points[1] = (lv_point_t){100,100};
lv_line_set_points(line1, line_points, 2);

line_points[2] = (lv_point_t){100,100};
line_points[3] = (lv_point_t){400,100};
lv_line_set_points(line1, line_points, 4);

// But, the following will draw only one line(the last one)
static lv_point_t line_points[2];
line_points[0] = (lv_point_t){100,30};
line_points[1] = (lv_point_t){100,100};
lv_line_set_points(line1, line_points, 2);

line_points[0] = (lv_point_t){100,100};
line_points[1] = (lv_point_t){400,100};
lv_line_set_points(line1, line_points, 4);

Why can’t lv_line_set_points() use “line1” to draw the two separate lines above?
So, just draws line connecting the two points provided, and forget about previous lines/points.
This way I always declare static lv_point_t line_points[2]; instead of static lv_point_t line_points[4]; or worse: static lv_point_t line_points[30000];
Don’t worry about what happens if user scrolls, I can have loop to re-draw.

In Windows I remember they used to have two wonderful methods: moveto(x1,y1), lineto(x2,y2), and no “overhead” arrays are involved.
I wish lvgl have something like that.

You still need to store x1, y1 and x2, y2 somewhere. And if you have 30k points you need to store 30 k x and y for moveto and lineto.

Maybe the drawing feature of lv_canvas are useful in your case: Canvas (lv_canvas) — LVGL documentation

You can, but you do not really need to store them. You can generate them dynamically at drawing time.
Here is an explanation:
Lets say I have 100 points of temperature readings to plot.
I cannot pass them directly to line_points[] array, because I have to:
1- Invert Y-axis, since top of Y is zero, and it increases downward, but to plot, I want the reverse behavior.
2- Need to apply some scaling.
3- Then convert them to integers.
After that I can pass them as integer numbers to line_points[] array.
Once this is done, I still cannot get rid of the original float array that has the temperature numbers, because if user clicks on screen I need to show the actual values at point of click. This I retrieve it from the temperature float array.
This means I need two arrays: Float to store actual temperature values, and an integer array to store the plotting points.
This is the way lvgl works now. It is very convenient because if user scrolls, the plot scrolls with it, and
the developer does not have to do anything. So, for small number of plotting points, convenience trumps the extra memory usage (of two arrays)

But if the plotting points are say 20k, then the second array (line_points[]) is not desirable. Here, memory concerns trumps convivence.
I do not need the second array to store points. I can run a “for loop” that converts floats to plotting point, and plot them using generic memoryless methods like drawline(), or lineto(). This eliminates the second array resulting in big memory saving of 20k.
Yes, it is less convenient because if user scrolls, then me as developer I have to run the “for loop” again to generate the plotting points, and adjust the plotting position.
Yes, I have to do what lv_line_set_points[] was doing automatically. So, with large number of data, the saving in memory is more important than the ease, and convenience in displaying the data.
Most graphics libraries have moveto(), drawline(), and lineto(). They take only x,y numbers (not array). drawline() takes also Pen which you specify its:
1- Thickness
2- Color
3- Whether it is line of dots, dash/dot, or continuous.

1- For small number of data to plot, lvgl provides very convenient way using double arrays of line_points[], and your original array.
2- For large number of plotting points, lvgl model is very costly. You get hit with two arrays instead of just the original one.

In C# they have multiple methods to draw lines. Here is one of them (least expensive in memory):
public void DrawLine (System.Drawing.Pen pen, int x1, int y1, int x2, int y2);
Please see: Graphics.DrawLine Method (System.Drawing) | Microsoft Docs

See here no array is used…big saving in memory. I just pass numbers to DrawLine() which I can generate dynamically (on the fly) in “for loop”.
BTW: In C# they do also have DrawLine() method that requires an array of points like line_points[].

I see. I suggest adding a draw event to an lv_obj where you call LVGL’s draw functions.

See this example. It draws a text but the gist is the same.