On 09/28/16 06:49, Spacen wrote:
> Beware of large amounts of rows. FLTK keeps an array that remembers
> the size of each row, this uses a lot of memory.
Hmm, no.
There are only two arrays internal to Fl_Table, which are only integers:
_colwidths -- width of each column
_rowheights -- height of each row
This lets columns be different widths and rows be different heights.
So if you have 1000 rows and 1000 columns, that's 2000 integers.
The rest of the data in Fl_Table are small data; non-arrays.
There's also a separate class Fl_Table_Row, which derives from Fl_Table,
and only has extra a single array of chars, used to keep track of the
selection state of each row: _rowselect
So if you have 10,000 rows, that's an extra 10,000 chars in memory.
That's it really.. there's no large data in either of these widgets.
> I once made a test
> version that did not have this problem by making the rows fixed height,
> otherwise you can just store when the hight differs from dfault.
I don't think making the heights fixed should matter; there's
it still keeps track of them the same way, fixed or different.
I can only think you were using a really early version of
Fl_Table that needed some optimization.
It should be very snappy.
> Also, I seem to remember another problem related to this, where the
> table code took ages to add up the size of each row.
Shouldn't be.
Try the test/table program.
By default it creates a 500 column / 500 row table.
In the UI you can change the #rows and #cols.
Change them to 100,000 x 100,000 -- it should still be very snappy
when you scroll around.
And the memory footprint should be tiny.
I'm using 1.3 SVN current in my test.
Regarding table data, Fl_Table does not manage data at all,
it handles display only, so it doesn't have any memory implications
for data.
Data is managed by your derived class. In some applications one can
generate the data live on demand, and wouldn't have to keep data in memory at all.
(test/table is an example of this, since the cell's data is procedurally generated)
When you use Fl_Table, you override the function that draws each
cell, and it only draws cells visible on screen. So if you have a
100k x 100k table, but only 50 are visible on the screen, only those
50 cells will be requested to be drawn by your function.
Fl_Table tells you the row and column number,
and you just draw whatever data should be at that position.