realbasic-nug
[Top] [All Lists]

Re: Efficient Lisbox RowTag Implementation

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Efficient Lisbox RowTag Implementation
From: Karen <keatk at verizon dot net>
Date: Sat, 31 May 2008 20:10:33 -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
References: <1F5D7379-4B88-4ABE-81F8-064A4F575B16 at verizon dot net> <130ABECA-AB7F-49ED-A38A-3FD5B2678E13 at great-white-software dot com> <0AE2C30C-A4B8-4399-959F-E430A44C2EB2 at verizon dot net> <30E9461B-81AC-4ADF-B4DE-F5D13EAD8BFB at great-white-software dot com>
On May 31, 2008, at 12:41 PM, Norman Palardy wrote:

> On 31-May-08, at 9:53 AM, Karen wrote:
>
>> Unfortunately users don't have all that info and would have to try
>> and figure it out empirically...
>>
>> Does anyone have feel for these numbers?
>>
> I'd suspect that the number of bytes difference is very small maybe 4
> or 8



I just simulated memory usage for all 4 approaches to implementing  
RowTags is a listbox:

1) Put a 2D variant array in the CellTag of row 0
2) Use 2 Dictionaries and put an integer key in the CellTag of row 0
3) Create a class with two tag properties and store an instance of  
the CellTag of row 0
4) Use the new Pair class  and store an instance of the CellTag of row 0

In all cases I assume that NOTHING is stored in the CellTag of row 0  
UNTIL either a RowTag or a cell tag is stored in that row. I  
simulated 10,001 rows with tags of ether sort and looked at memory  
usage when storing only one type of tag and then both types of tag  
values. I used the integer 1 for tag values in all cases.

The results surprised me... using my own class class or the pair  
class won unambiguously!


Approach                1 Tag Value             2 Tag Values

My Class                  659456                    978944
Pair Class                659456                    978944
Array                     978944                   1314816
2 Dictionaries           1540096                   2641920

---------------------------
Using my own Class:

   Dim Holder(10001) as Variant
   Dim MStart, MEnd as double

   MStart = Runtime.MemoryUsed

   For i as integer = 0 to 10000
     Holder(i) = New TagHolder
   Next

   MEnd = Runtime.MemoryUsed
   Dim C as new Clipboard
   C.Text = Format(MEnd - Mstart,"0")


   Class TagHolder
      Sub Constructor()
        CellTag = 1
        'RowTag = 1
      End Sub
      Property:RowTag As Variant
      Property:CellTag As Variant
   End Class

---------------------------
Using Pair Class:

   Dim Holder(10001) as Variant
   Dim MStart, MEnd as double

   MStart = Runtime.MemoryUsed

   For i as integer = 0 to 10000
     Holder(i) = New Pair(1,NIL)
     'Holder(i) = New Pair(1,1)
   Next

   MEnd = Runtime.MemoryUsed
   Dim C as new Clipboard
   C.Text = Format(MEnd - Mstart,"0")

---------------------------
Array approach

   Dim Holder(10001) as Variant
   Dim MStart, MEnd as double

   MStart = Runtime.MemoryUsed

   For i as integer = 0 to 10000
     Holder(i) = VArrMaker
   Next

   MEnd = Runtime.MemoryUsed
   Dim C as new Clipboard
   C.Text = Format(MEnd - Mstart,"0")

   Function VArrMaker() As Variant
     Dim VArr(1) as Variant
     VArr(0) = 1
     'VArr(1) = 1
     Return VArr
   End Function
---------------------------
Dictionary approach

   Dim Holder(10001) as Variant
   Dim MStart, MEnd as double

   MStart = Runtime.MemoryUsed

   Dim D1 As New Dictionary
   Dim D2 As New Dictionary

   For i as integer = 0 to 10000
     Holder(i) = 1  ' Assigning key value to CellTag
     D1.Value(i) = 1
     'D2.Value(i) = 1
   NExt

   MEnd = Runtime.MemoryUsed

   Dim C as new Clipboard
   C.Text =Format(MEnd- MStart,"0")
_______________________________________________
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>