Alternative to a Long While

Please discuss general Delphi programming topics here.

Alternative to a Long While

Postby sepehr » March 16th, 2007, 11:04 am

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
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Kambiz » March 16th, 2007, 2:22 pm

What you want to achieve is not clear at all.

Could you please clarify the goal?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Johnny_Bit » March 16th, 2007, 4:46 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
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby sepehr » March 17th, 2007, 10:33 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
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Kambiz » March 17th, 2007, 12:26 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby sepehr » March 17th, 2007, 5:54 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?

thanks for answering
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Johnny_Bit » March 18th, 2007, 8:28 am

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
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby sepehr » March 18th, 2007, 1:11 pm

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?
User avatar
sepehr
Active Member
Active Member
 
Posts: 23
Joined: October 4th, 2006, 6:38 am
Location: Karaj

Postby Johnny_Bit » March 18th, 2007, 10:28 pm

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
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron