DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Alternative to a Long While

 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> Delphi Programming
View previous topic :: View next topic  
Author Message
sepehr
Member


Joined: 04 Oct 2006
Posts: 15
Location: Karaj

PostPosted: 16/03/07 11:04    Post subject: Alternative to a Long While Reply with quote

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
View user's profile Send private message Yahoo Messenger
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 16/03/07 14:22    Post subject: Reply with quote

What you want to achieve is not clear at all.

Could you please clarify the goal?

_________________
Kambiz

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Johnny_Bit
Administrator


Joined: 15 Jun 2003
Posts: 397

PostPosted: 16/03/07 16:46    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sepehr
Member


Joined: 04 Oct 2006
Posts: 15
Location: Karaj

PostPosted: 17/03/07 10:33    Post subject: Reply with quote

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! Wink
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
View user's profile Send private message Yahoo Messenger
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1231
Location: Tehran, Iran

PostPosted: 17/03/07 12:26    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sepehr
Member


Joined: 04 Oct 2006
Posts: 15
Location: Karaj

PostPosted: 17/03/07 17:54    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
Johnny_Bit
Administrator


Joined: 15 Jun 2003
Posts: 397

PostPosted: 18/03/07 08:28    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sepehr
Member


Joined: 04 Oct 2006
Posts: 15
Location: Karaj

PostPosted: 18/03/07 13:11    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
Johnny_Bit
Administrator


Joined: 15 Jun 2003
Posts: 397

PostPosted: 18/03/07 22:28    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> Delphi Programming All times are GMT
Page 1 of 1

Add to favorites

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group