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>
|