Page 1 of 1
Alternative to a Long While

Posted:
March 16th, 2007, 11:04 am
by sepehr
- Code: Select all
Var
From2Loop:Int64
AllPass:TStringList;
Begin
AllPass:=Tstringlist.Create;
While 1< 999999999999999999 do
Begin
AllPass.Add(IntToStr(From2Loop));
From2Loop:=From2Loop+1;
End;
End;
i want to add all of that big numbers to my Stringlist(which is allpass)
1.is it possible to have that much items in a stringlist?
2.if yes is there a better way so i can substitute with this while?because
most of the time the application freezes
thanks Before

Posted:
March 16th, 2007, 2:22 pm
by Kambiz
What you want to achieve is not clear at all.
Could you please clarify the goal?

Posted:
March 16th, 2007, 4:46 pm
by Johnny_Bit
Wait, what? You want to do a loop that creates 999999999999999999 elements? You don't let your app process messages? You wonder why it freezes? And besides that, if every item had size of 1 byte 999999999999999999 of them would be around 888 petabytes (dunno, I could be mistaken). They actually are way bigger. Now what the hell you want to do?

Posted:
March 17th, 2007, 10:33 am
by sepehr
Johnny_Bit wrote:Wait, what? You want to do a loop that creates 999999999999999999 elements? You don't let your app process messages? You wonder why it freezes? And besides that, if every item had size of 1 byte 999999999999999999 of them would be around 888 petabytes (dunno, I could be mistaken). They actually are way bigger. Now what the hell you want to do?
Chill Out Man!
i am trying to put a long range of numbers to a text file, i haven't done anything yet, the given code was just an example,i wonder if that is possible

Posted:
March 17th, 2007, 12:26 pm
by Kambiz
Why you've used a TStringList? Write the numbers in to the file.
- Code: Select all
var
F: TextFile;
N: Integer;
begin
AssignFile(F, 'Numbers.txt');
Rewrite(F);
try
for N := 1 to 100 do
Writeln(F, N);
finally
CloseFile(F);
end;
end;
Anyway, Johnny is right.

Posted:
March 17th, 2007, 5:54 pm
by sepehr
yes you are right, but i have to do some processes after numbers are stored somewhere (in the main memory) then save it to a file and beside saving to a file i need them later on the rest of my code,that's why i used stringlist,can u offer something like that?
thanks for answering

Posted:
March 18th, 2007, 8:28 am
by Johnny_Bit
Why stringlist then? It's so lame and slow... You want to deal with numbers? No problem, just use TList of pointers to integers or something like that... besides Delphi does have dynamic arrays that are fast, why not use them? And whatever fits you I must say that C++'s STL vector is great for that kind of things.
//Faux pas intended.

Posted:
March 18th, 2007, 1:11 pm
by sepehr
Thanks so informative,and another thing,suppose that i have saved 100000 names in a text file,now i wanna sort the names and resave it,what do you suggset me to do?

Posted:
March 18th, 2007, 10:28 pm
by Johnny_Bit
Hmm.. 2MB file with names, and you want to sort it? When you get to big numbers of data records it's way better to use specialized DB. I know it's way around the problem, but that's just how the things roll among Lazy ones.
Besides how would you achieve that kind of sort with StringList? I (only if I was forced to do so) would use list of pointers to packed records containing interesting data and use quick sort or whatever is appropriate for the task to do it as fast as possible on List elements.
Once you get to the dark side of Pointer Magic you won't ever go back.