too much thinking?

This is a discussion on too much thinking? within the Windows Programming forums, part of the Platform Specific Boards category; so my program likes to blank out when it has too much thinking to do.. http://img.photobucket.com/albums/v4...chThinking.jpg the point where it ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    too much thinking?

    so my program likes to blank out when it has too much thinking to do..
    http://img.photobucket.com/albums/v4...chThinking.jpg

    the point where it does this is when its searching inside a large number of files for a certain keyword or keywords.
    how can i prevent this from happening? thanks
    Last edited by willc0de4food; 10-02-2006 at 06:07 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Make the process that's causing the stall a separate process/thread and that way it shouldn't have such an adverse affect on painting or user input.

    Or look again at the resource-hogging process and see if you can't improve the way it does what it does.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    i like the way you think...
    but i tried making the process a seperate thread, however with what i have currently when i try to execute the seperate thread, i get an access violation.
    i believe the violation exists somewhere in here..
    Code:
    DWORD WINAPI PreSearch(LPVOID lParam)
    {
         HWND hwnd = (HWND)lParam;
    ?
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    You have to understand that your entire program is dependent on the windows message loop to do all sorts of things (like respond to key presses, redraw the window, do the actual work).

    You have to break up your search into more manageable chunks. An easy way to do this is to create a 'state' which records where you're at.
    eg
    Code:
    struct state {
      vector<string> filenames;
      int currentfile;
      vector<string> results;
      bool updated;
    } state;
    On each WM_TIMER event say, you search the next file in the list and then return. If you found something, append to the results, and set updated to true.

    When the redraw code next happens, it will see the state.updated and proceed to update the window with the latest search results.

    This can be extended to searching directories for lists of files (like only search one dir at once, and have a queue of directories still to be searched).
    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.

  5. #5
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm.....so would i add code for processing to the wm_timer case? or leave the code in the function i have it in, and then when the wm_timer case gets sent a message have the struct there with the current file that the function is on and have it continue processing the next file. then once that file is processed, release control until the wm_timer case gets its turn again?
    or am i completely missing it? lol
    would it be possible for some pseudo-code? if you're that bored thatd be sweet...

    thanks :]
    Registered Linux User #380033. Be counted: http://counter.li.org

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    > release control until the wm_timer case gets its turn again?
    Yes, that's it.

    Basically, you have to slice the task up into manageable bits.

    Or you could use threads as mentioned by Ken, but that brings in a whole bunch of other problems to do with access to shared data.
    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.

  7. #7
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm...so how do i know when wm_timer gets its turn? something like
    Code:
    if (WM_TIMER)
    {
    // CODE
    }
    ? i dont imagine thatd be a good way of doing things but i've been wrong in the past. lol
    Registered Linux User #380033. Be counted: http://counter.li.org

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    The WM_TIMER message gets posted to your window like any other message. Just handle it in your window procedure's case statement, and perform a chunk of your processing as Salem suggested.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    Code:
    struct state {
      vector<string> filenames;
      int currentfile;
      vector<string> results;
      bool updated;
    } elephant;
    
    ...
    case WM_TIMER:
      take_a_bite( &elephant );
      break;
    Just keep nibbling away until you've eaten the elephant - no indegestion
    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.

  10. #10
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    hahaha. i think i get it now.
    i'll have to test it out later...
    thanks :]


    but i dont know if the conversion from .c to .cpp is going to go over too well for my program... =\
    Last edited by willc0de4food; 10-03-2006 at 06:12 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thinking of upgrading to linux...
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 07-24-2009, 11:40 AM
  2. thinking about making a network traffic monitor
    By jimjamjahaa in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2005, 11:38 AM
  3. Thinking of Modding Xbox. Don't know about Linux
    By Stan100 in forum Linux Programming
    Replies: 4
    Last Post: 05-30-2004, 04:51 PM
  4. Replies: 3
    Last Post: 04-22-2004, 10:49 PM
  5. Fluid Thinking
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 11-20-2002, 02:29 PM

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