Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:11 pm
by Eric Peachey >> Thu, 21 Jan 1999 23:03:44 GMT
Hello,
Beware of large StringArray and HugeStringArray objects. If you want to manipulate large arrays of strings then you'll find it heaps quicker to define your own string object class (has one attribute of String of maximum size)and a collection (say a Set or ExternalKeyDictionary) for storing your string objects. Access to your string objects in your collection will be vastly quicker than going through a StringArray or HugeStringArray.
Below is a defintion of a simple class and collection and a JadeScipt method for you to try out.
Have fun.
Eric Peachey
//****************************
STRING OBJECT CLASS DEFINTION...
//*********************************************
typeDefinitions
StringObject completeDefinition
(
attributeDefinitions
id: Integer;
myString: String;
)
//***************************************
MemberKeyDictionary for storing StringObjects
//****************************************************
typeHeaders
StringObjectDict subclassOf MemberKeyDictionary transient, number = 2131;
membershipDefinitions
StringObjectDict of StringObject ;
typeDefinitions
StringObjectDict completeDefinition
(
)
memberKeyDefinitions
StringObjectDict completeDefinition
(
id;
)
// **********************************
THE METHOD!!!
//*******************************************
testArrays();
vars
hsa : HugeStringArray;
so : StringObject;
sod : StringObjectDict;
s : String;
i : Integer;begin
write 'Creating objects...';
create hsa transient;
create sod transient;
write 'Populating collections...';
while i < 500 do
hsa.add( "Hello, I'm string number " & i.String );
create so transient;
so.id := i;
so.myString := "Hello, I'm string number " & i.String;
sod.add( so );
i := i + 1;
endwhile;
write 'Going through HugeStringArray...';
write app.actualTime();
i := 0;
foreach s in hsa do
i := i + s.length;
endforeach;
write 'Total length of strings = ' & i.String;
write app.actualTime();
write 'Done!';
write 'Going through Dictionary...';
write app.actualTime();
i := 0;
foreach so in sod do
i := i + so.myString.length;
endforeach;
write 'Total length of strings = ' & i.String;
write app.actualTime();
write 'Done!';
epilog
delete hsa;
delete sod;
end;