Program chews up a lot of CPU when it closes

This is a discussion on Program chews up a lot of CPU when it closes within the Windows Programming forums, part of the Platform Specific Boards category; My program chews up a lot of the CPU for ~ min. It only does after I do my execution, ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53

    Unhappy Program chews up a lot of CPU when it closes

    My program chews up a lot of the CPU for ~ min. It only does after I do my execution, if I exit as soon as I launch it closes with no troubles. When I close after doing my processing(a lot of number crunching, two int arrays of 525000) It opens a binary file get all my data in and then I output to a text file, with a lot of number crunchin in the middle. After I am done and get back to my main Dialog, I hit the wait state and no CPU usage, I can even run the number crunch as many times as I want and will do less cpu chewing than when I exit. Any comments, or anyone else had this problem.

    I am leaning toward the large arrays that I have, because I tried using them in diffrent delcloration and got assertion failures, and another one kept giving me stack overflow problems.

    GUI interface was done using MFC - please hold the comments back about the cursed microSLOTH.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Are the arrays size hard coded or are you allocating them memory dynamically?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53
    There are 2 arrays are in an object that I declare dynamically,
    when I removed the dynamically declaration for the object, I got stack over flow problems.

    code as follows:

    arrays declared as follows within class

    const int MAX = 0x80000;

    class fixdump
    {
    private:
    int GPC_MEMORY[MAX];
    int storeprotect[MAX];
    int memcnt;
    ......... more stuff
    public:
    fixdump();
    ~fixdump();
    void execute_fix();
    };

    /////////////////////////////////////////////////////////////////////
    fixdump::fixdump()
    {
    first = true;
    memcnt = 0;
    footerval = 0;
    }
    /////////////////////////////////////////////////////////////////////
    fixdump::~fixdump()
    {
    }

    /////////////////////////////////////////////////////////////////////
    void fixdump::execute_fix()
    {

    int temp = 0;
    char *buff = new char;

    for(int i = 0; i < MAX; i++)
    {
    GPC_MEMORY[i] = 0;
    storeprotect[i] = 0;
    }

    TCHAR szFilters[] = _T ("All Files (*.*) |*.*|");
    CString pop;
    pop = "Please Select GPC MEMORY BINARY FILE";
    AfxMessageBox(pop, MB_OK);
    CFileDialog cdlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, szFilters);
    if(cdlg.DoModal() == IDOK)
    {
    CWaitCursor wait;

    fin.open(cdlg.GetPathName(), ios::binary);
    while(fin)
    {
    .....Crunch Numbers
    }
    fin.close();

    wait.Restore();
    output_dump(); // outputs array into file
    }

    return;
    }
    ///////////////////////////////////////////////////////////////////////////
    //chews CPU when closes
    void CBintodumpDlg::OnOK()
    {
    fixdump *fix = new fixdump;
    fix->execute_fix();//try threading
    fix->~fixdump();
    delete fix;
    }

    //Stack overflow problems, will not execute
    void CBintodumpDlg::OnOK()
    {
    fixdump fix;
    fix.execute_fix();
    }

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    my guess is Windows is cleaning up caches and other resource allocations made during the execution of your program.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Location
    Fort Worth, TX
    Posts
    53
    I would second that clean up explaination, but I changed the Release setting on MS VC++ from Debug to Release and My problem went away. I believe that in the Debug mode it was adding extra features so the debugger could have data for the developer to analysis and in release mode it no longer gathers that data. Thanks for all your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Help with Combo Box that closes my program
    By Marcos in forum Windows Programming
    Replies: 3
    Last Post: 06-05-2005, 11:09 PM
  3. Program uses a lot of memory and doesnt exit properly
    By TJJ in forum Windows Programming
    Replies: 13
    Last Post: 04-28-2004, 04:13 AM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM

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