How best to handle small lists? 
Author Message
 How best to handle small lists?

I would like some advice on how best to handle a small list.  The list
will rarely, if ever, hold more than 20 items. Each item is a user
defined type (UDT) which contains 3 integers, two singles, and two
single one dimension arrays containing 70 items each.

The typical list would contain about 5-10 items. Items will only be
added to the end of the list but any item can be deleted. I will need
to retrieve any item from the list based on user input (index from list
dialog). In addition, I will need to walk through the list (top to
bottom) to build the list dialog.

Here are what I think my choices are. What do you think is the best
method for maximum performance?

Dynamic Arrays
--------------

This seems the simpliest approach. I could add another member to my
UDT to indicate whether the a itme has been deleted. With such a small
list, I figured I would not worry about garbage collection. Just
resize the array by 10 everytime I ran out of room and not worry
about unused space. Unfortunately,I would have to loop through the
whole list to retrieve an item since the list dialog index number would
not match the list.

Collections
-----------

For what I read on this newsgroup, UDT are not support with collections.
I would have to incorporate the UDT in a class and add the class to
a collection. Seems like alot of overhead for a small list

Link List
---------

Should be the best option but again VB only allows the use of pointers
with objects. I would have to create a class for my UDT. Not sure
it is worth the effort for such a small list. Yes? No?

Thanks,

John Chauvin



Sat, 22 Nov 2003 02:45:45 GMT  
 How best to handle small lists?
John,

Create a class with properties as in UDT and collection class. It's simple
and elegant, much more easier to work with than UDT and arrays. For such a
small list I wouldn't care about performance or memory usage, but if you
aren't satisfied with perormance you can always change internals of the
classes without affecting other components.

Below is my simplest collection class template, don't forget to set
Procedure ID of Enumerator to -4 and make Item property default.

--
HTH,
Alexander Shirshov, MCSD

Option Explicit
'TODO: replace zzz with type name
Private m_Col As Collection

Public Property Get Item(IndexKey As Variant) As zzz
  Set Item = m_Col(IndexKey)
End Property

Public Property Get Count() As Long
  Count = m_Col.Count
End Property

Public Function Add() As zzz
  Dim newzzz As zzz
  Set newzzz = New zzz
  m_Col.Add newzzz
  Set Add = newzzz
End Function

Public Sub Remove(IndexKey As Variant)
    m_Col.Remove IndexKey
End Sub

Public Function Exists(Key As String)
  Dim Dummy As String
  On Error GoTo ErrHandler

  Dummy = TypeName(m_Col(Key))
  Exists = True
  Exit Function
ErrHandler:

End Function

Public Property Get Enumerator() As IUnknown
  Set Enumerator = m_Col.[_NewEnum]
End Property

Private Sub Class_Initialize()
  Set m_Col = New Collection
End Sub


Quote:

> I would like some advice on how best to handle a small list.  The list
> will rarely, if ever, hold more than 20 items. Each item is a user
> defined type (UDT) which contains 3 integers, two singles, and two
> single one dimension arrays containing 70 items each.

> The typical list would contain about 5-10 items. Items will only be
> added to the end of the list but any item can be deleted. I will need
> to retrieve any item from the list based on user input (index from list
> dialog). In addition, I will need to walk through the list (top to
> bottom) to build the list dialog.

> Here are what I think my choices are. What do you think is the best
> method for maximum performance?

> Dynamic Arrays
> --------------

> This seems the simpliest approach. I could add another member to my
> UDT to indicate whether the a itme has been deleted. With such a small
> list, I figured I would not worry about garbage collection. Just
> resize the array by 10 everytime I ran out of room and not worry
> about unused space. Unfortunately,I would have to loop through the
> whole list to retrieve an item since the list dialog index number would
> not match the list.

> Collections
> -----------

> For what I read on this newsgroup, UDT are not support with collections.
> I would have to incorporate the UDT in a class and add the class to
> a collection. Seems like alot of overhead for a small list

> Link List
> ---------

> Should be the best option but again VB only allows the use of pointers
> with objects. I would have to create a class for my UDT. Not sure
> it is worth the effort for such a small list. Yes? No?

> Thanks,

> John Chauvin



Sat, 22 Nov 2003 03:51:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How best to handle a small list?

2. Best way to handle opening small recordsets repeatedly

3. How To Handle List Codes and List Text

4. Handling Large/Small Fonts?

5. Access List ctrl = Good / VB List ctrl = Crap ???

6. Small but getting better

7. Best dev-tool for small database app?

8. Best Sql Database for small systems

9. Thingamig that lists (Small Pic Attached)

10. Small icons in a list box

11. ListBox.List Too Small !!

12. small icons for tree and list views

 

 
Powered by phpBB® Forum Software