Thread: Efficiency with c++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Is your program single threaded? If so, write the data in a separate thread so you can begin with the next read before the write is finished.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by medievalelks View Post
    Is your program single threaded? If so, write the data in a separate thread so you can begin with the next read before the write is finished.
    You don't even need threads for that, just use "OVERLAPPED" IO - it makes life easier to just do that. Just remember that you need more than one buffer to read/write overlapped IO, since you can't be reading into the same buffer that is being written [or strange things will happen].

    Edit: To change your tasks priority, check out the example in MSDN SetPriorityClass.

    --
    Mats
    Last edited by matsp; 08-08-2008 at 06:54 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    Ive have 2 seperate buffers, 1 for reading and 1 for writing and i have just added (LPOVERLAPPED) to my code so hopefully everything should work out ok for that. Just so i get an understandiung of this "LPOVERLAPPED" creates a more efficient input/output operation, allowing both to happen at the same time rather than waiting to read, then waiting to write so on?

    Im going to check that example out now matsp

    thanks for this help everyone

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by pastitprogram View Post
    Ive have 2 seperate buffers, 1 for reading and 1 for writing and i have just added (LPOVERLAPPED) to my code so hopefully everything should work out ok for that. Just so i get an understandiung of this "LPOVERLAPPED" creates a more efficient input/output operation, allowing both to happen at the same time rather than waiting to read, then waiting to write so on?
    Correct - you do not wait for each operation to finish.

    Note that you can't just issue lots of overlapped reads/writes. You will need to issue one read, then issue a second read, wait for the first read to complete, then issue the write for the first read data. Then you start waiting for the second read, and then issue the write for the second dataset, etc, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Whenever I run the program it hogs all my computers resources making it impossible to do anything else until my program has finished
    In those kind of case where you have a non-critical process running in background, you normally want the process to have an above normal priority. Here's another link about process/thread priorities on Windows http://msdn.microsoft.com/en-us/libr...00(VS.85).aspx

    Or since your application consist of mostly I/O operation (if not exclusively), you could also think of disabling priority boost, which happens when an I/O operation complete (I'm not sure but I guess it's still true with asynchronous I/O). I'm not sure if it would help. You could try experimenting and see what it gives.
    I hate real numbers.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    right ive been having a mess around with it now and ive implemented some options to change its priority. By implementing it as below average priority, as long as im not hammering my computer with other processes and things the performance of my program seems to be quite good which im pleased with. I believe as well that the overlapped function into my read and write buffers and upping the buffer size has also speed the whole situation up as it appears to be going faster than i remember it doing. Thank you everyone for your help, it has been very much appreciated and given me a totally new insight into building further programs. u learn something new every day!

    cheers guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating space efficiency using sizeof()
    By markcls in forum C Programming
    Replies: 6
    Last Post: 05-19-2007, 05:25 AM
  2. Efficiency problems
    By Crazy Glue in forum C# Programming
    Replies: 15
    Last Post: 07-20-2006, 08:38 AM
  3. Programme Efficiency
    By Cikotic in forum C Programming
    Replies: 3
    Last Post: 06-28-2004, 01:29 PM
  4. Binary tree search efficiency
    By ExCoder01 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-23-2003, 10:11 PM
  5. Algorithm Efficiency
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2002, 06:45 PM