how to speed the program with bcb?

This is a discussion on how to speed the program with bcb? within the C++ Programming forums, part of the General Programming Boards category; Code: typedef struct AList { int no1; int no2; int no3; int no4; int no5; } TAList; typedef TAList* PAList; ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    11

    how to speed the program with bcb?

    Code:
    typedef struct AList
    {
      int no1;
      int no2;
      int no3;
      int no4;
      int no5;
      
    } TAList;
    typedef TAList* PAList;
    
    TList * ResultList;
    
    
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        randomize();
        ResultList = new TList;  
    }
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
     DWORD StartTime,EndTime,LastTime;
     StartTime=GetTickCount();  //
        for(int i=0;i<100000;i++)
        {
                PAList AStruct;
                AStruct = new TAList;
                AStruct->no1=random(10);
                AStruct->no2=random(10);
                AStruct->no3=random(10);
                AStruct->no4=random(10);
                AStruct->no5=random(10);
                ResultList->Add(AStruct);
             
        }
    
             for(int i=0;i<Form1->ResultList->Count-1;i++)
             {
                    PAList AStruct;
                     AStruct = new TAList;
                     AStruct = (PAList) ResultList->Items[i];
                  for(int j=i+1;j<Form1->ResultList->Count;j++)
                  {
                     PAList BStruct;
                     BStruct = new TAList;
                     BStruct = (PAList) ResultList->Items[j];
                     int iSame=0;
                     if(AStruct->no1==(BStruct->no1+1)) continue;
                     if(AStruct->no2==(BStruct->no2+1)) continue;
                     if(AStruct->no3==(BStruct->no3+1)) continue;
                     if(AStruct->no4==(BStruct->no4+1)) continue;
                     if(AStruct->no5==(BStruct->no5+1)) continue;
    
                     ResultList->Delete(j);j--;                  
                     delete BStruct;
                  }
    
           }
    
    EndTime=GetTickCount();  
    LastTime=EndTime-StartTime;
    Application->MessageBoxA(IntToStr(LastTime).c_str(),"time used",MB_ICONEXCLAMATION);       
    }
    
    void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
          if(ResultList->Count>0)
          for(int i=ResultList->Count-1;i<-1;i--)
          {
                     PAList AStruct;
                    AStruct = new TAList;
                    AStruct =(PAList) ResultList->Items[i];
                    ResultList->Delete(i);  
                    delete[] AStruct;
    
          }
    }

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    9
    At first sight, use a static array instead of TList.


    and, you have a memory leakage here (and on other places)
    AStruct = new TAList;
    AStruct = (PAList) ResultList->Items[i];
    Last edited by epic; 03-17-2004 at 05:04 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    Is this just an exercise, or is there some big plan for doing this?

    > for(int i=0;i<100000;i++)
    Because it seems to me that you create a million sets of random values, then filter them in some way, and hope that there are enough sets which satisfy some condition for you to work with later on.

    Perhaps explaining what you are trying to achieve with all this would be helpful.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    11
    i could not replace tlist by array,for i do not know the size of the list.
    my software is designed for this: i have 12 columns,every column has 0,1,2,3 or Multiselect choices,to select one for each columns to form a thing,just like012000011133,so there has 16777216 choice at total,and i want to filter some choice,what can i do

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 12:40 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 09:04 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21