469,592 Members | 1,674 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Array advice

I am converting a VB6 App.

In the VB6 app, I have a Type structure of about 30 elements (mixture of
booleans, integers, strings and some doubles), in an array of say 20 to
100+ records.

The size of the array doesn't change that frequently, so the speed of
inserting and removing records is not that important. However, the
speed of finding, and read/writing of the elements is very import.
Needs to be thread safe too.

Am I best sticking with setting up a Structure, and attaching it to an
array, manually sizing it, and recursively searching though it, or is
there a better alternative?

Thanks,
Stuart.

Nov 20 '05 #1
1 901
Create a sorted secondary array with your most searched item. Then you can
use a binary seach to find what you want quicky.

Example;
'-- Your struct array
mystruct(0).name="Mark"
mystruct(0).Id = 152437

mystruct(1).name="Bob"
mystruct(1).Id = 23437

mystruct(2).name="Chuck"
mystruct(2).Id = 37674

mystruct(3).name="Mr Cool"
mystruct(3).Id = 17222

mystruct(4).name="Terry"
mystruct(4).Id = 7865

mystruct(5).name="Dufuss"
mystruct(5).Id = 67543

'-- Sorted Secondary Array:

Dim sortedArray(5) as Integer

'-- These are sorted by name
sortedArray(0) = 1 '-- Bob
sortedArray(1)=2 '-- Chuck
sortedArray(2)=5 '-- Dufuss
sortedArray(3)=0 '-- Mark
sortedArray(4)=3 '-- Mr Cool
sortedArray(5)=4 '-- Terry

Then use a binary search on this array and not you struct array. You can
also create another sorted array for the id's if you wish.


"Stuart" <st****@stu.org.uk> wrote in message
news:bp*************@ID-17980.news.uni-berlin.de...
I am converting a VB6 App.

In the VB6 app, I have a Type structure of about 30 elements (mixture of
booleans, integers, strings and some doubles), in an array of say 20 to
100+ records.

The size of the array doesn't change that frequently, so the speed of
inserting and removing records is not that important. However, the
speed of finding, and read/writing of the elements is very import.
Needs to be thread safe too.

Am I best sticking with setting up a Structure, and attaching it to an
array, manually sizing it, and recursively searching though it, or is
there a better alternative?

Thanks,
Stuart.

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by csx | last post: by
5 posts views Thread by Denis Perelyubskiy | last post: by
8 posts views Thread by eft0 | last post: by
7 posts views Thread by Oleg Konovalov | last post: by
5 posts views Thread by WesIdell | last post: by
20 posts views Thread by Gustaf | last post: by
272 posts views Thread by Peter Olcott | last post: by
7 posts views Thread by alternative451 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.