C
C#2mo ago
Klarth

Data structure options for UI virtualization

I'm trying to find a good data structure for UI virtualization of collection controls to keep track of each control's estimated dimensions. Virtualization is (eg.) when you have a million data rows and only 10 can fit on screen, so you only create 10 controls. As the user scrolls, controls that move offscreen are recycled (returned to pool) and rows that now appear onscreen are materialized as controls. Because only on-screen controls exist, I cannot store row-specific metadata on them to later retrieve because they get wiped during recycling. The main problem I'm trying to solve is obtaining the total height of all rows when row heights can vary: combining actual measurements from rows that have been previously materialized and estimated heights for ones that haven't. While I could store row height information in a standard array, typical insert and delete operations will result in large move operations. I'm looking for a better solution than one giant array (or an array of chunks). Ideally, I could index the structure by the row ID in the collection control (ie. [0-1,000,000]), but I could also accept an ID that's stored on the data (instead of part of UI). I'm worried about Dictionary having an unacceptably large memory footprint.
2 Replies
LPeter1997
LPeter19972mo ago
What about a ConditionalWeakTable? Mapping items (assuming they are unique) to any extra data you need If not then it would be the same as Dictionary, but I'd definitely try to have CWT worked in to have auto-release for removed rows somehow
Klarth
KlarthOP2mo ago
Hmm, that may work. Worth a shot when I prototype since it's an off-the-shelf implementation.
Want results from more Discord servers?
Add your server