| View previous topic :: View next topic |
| Author |
Message |
sepehr Member
Joined: 04 Oct 2006 Posts: 15 Location: Karaj
|
Posted: 16/03/07 11:04 Post subject: Alternative to a Long While |
|
|
| Code: |
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
|
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 16/03/07 14:22 Post subject: |
|
|
What you want to achieve is not clear at all.
Could you please clarify the goal?
_________________ Kambiz
 |
|
| Back to top |
|
 |
Johnny_Bit Administrator
Joined: 15 Jun 2003 Posts: 397
|
Posted: 16/03/07 16:46 Post subject: |
|
|
| 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?
|
|
| Back to top |
|
 |
sepehr Member
Joined: 04 Oct 2006 Posts: 15 Location: Karaj
|
Posted: 17/03/07 10:33 Post subject: |
|
|
| 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
|
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1231 Location: Tehran, Iran
|
Posted: 17/03/07 12:26 Post subject: |
|
|
Why you've used a TStringList? Write the numbers in to the file.
| Code: | 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
 |
|
| Back to top |
|
 |
sepehr Member
Joined: 04 Oct 2006 Posts: 15 Location: Karaj
|
Posted: 17/03/07 17:54 Post subject: |
|
|
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
|
|
| Back to top |
|
 |
Johnny_Bit Administrator
Joined: 15 Jun 2003 Posts: 397
|
Posted: 18/03/07 08:28 Post subject: |
|
|
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.
|
|
| Back to top |
|
 |
sepehr Member
Joined: 04 Oct 2006 Posts: 15 Location: Karaj
|
Posted: 18/03/07 13:11 Post subject: |
|
|
| 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?
|
|
| Back to top |
|
 |
Johnny_Bit Administrator
Joined: 15 Jun 2003 Posts: 397
|
Posted: 18/03/07 22:28 Post subject: |
|
|
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.
|
|
| Back to top |
|
 |
|