## Alternative to a Long While

Please discuss general Delphi programming topics here.

### Alternative to a Long While

Code: Select all
VarFrom2Loop:Int64AllPass: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

sepehr
Active Member

Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

What you want to achieve is not clear at all.

Could you please clarify the goal?
Kambiz

Kambiz

Posts: 2424
Joined: March 7th, 2003, 7:10 pm

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?
Johnny_Bit
VIP Member

Posts: 455
Joined: June 15th, 2003, 9:56 am

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

sepehr
Active Member

Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

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.
Kambiz

Kambiz

Posts: 2424
Joined: March 7th, 2003, 7:10 pm

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?

sepehr
Active Member

Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

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.
Johnny_Bit
VIP Member

Posts: 455
Joined: June 15th, 2003, 9:56 am

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?

sepehr
Active Member

Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

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.
Johnny_Bit
VIP Member

Posts: 455
Joined: June 15th, 2003, 9:56 am