realbasic-nug
[Top] [All Lists]

Efficient Lisbox RowTag Implementation

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Efficient Lisbox RowTag Implementation
From: Karen <keatk at verizon dot net>
Date: Fri, 30 May 2008 21:50:07 -0400
Authentication-results: mx.google.com; spf=pass (google.com: domain of realbasic-nug-bounces at lists dot realsoftware dot com designates 66.116.103.65 as permitted sender) smtp dot mail=realbasic-nug-bounces at lists dot realsoftware dot com
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
I like to add efficient functionally to subclasses of controls for  
future use. Because I want them to be general purpose, for some uses  
speed would be most important and in others memory usage would be  
most important ... So I try to do the best I can balancing the two.

Someone (i think Norm) talked about how they implemented a ListBox  
RowTag by using a dictionary (or two?), overriding the  
ListBox.CellTag getter and setter and adding RowTag getter and  
setters with the Dictionary key being being stored in the CellTag for  
column 0.

In the past I did the same sort of thing by creating an object with  
two variant properties (one for RowTag and one for CellTag) and  
storing that in the CellTag for column 0. But after see the above  
approach, it occurred to me that the memory overhead for object  
creation would likely be significantly higher for the object approach  
for PERHAPS a negligible increase in access speed. So I thought the  
dictionary approach was probably superior...

But these days variants can store arrays so I thought why not store a  
two element variant array in the CellTag for column 0 instead of  
using a dictionary or an object. That MIGHT both be faster and more  
memory efficient that either of the above solutions... What do you  
think? What type of situation would this be better or worst for?

But don't tell me I should not worry about it! ;)

Here are example getter and setters for example: (TagRowIdx and  
TagCellIdx are constants)

---------
Function CellTag(row as integer, column As integer) As Variant
   If Column > 0 then Return Super.CellTag(row,column)

   Dim V as Variant = Super.CellTag(row,0)

   If V Is Nil then Return V
   Dim TagArray() as Variant = V

   Return TagArray(TagRowIdx)
End Function

----------
Sub RowTag(row as integer, Assigns Tag as variant)
   Dim V as Variant = Super.CellTag(row,0)

   If V Is Nil then
     Dim TagArray(1) As Variant
     TagArray(TagRowIdx) = Tag
     Super.CellTag(row,0) = TagArray
   Else
     Dim theArray() as Variant = V
     theArray(TagRowIdx) = Tag
   End if
End Sub
----------

Thanks
- Karen

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>