Results 1 to 40 of 62

Thread: VB6 Threading-Examples using the vbRichClient5 ThreadHandler

Threaded View

  1. #12

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 Threading-Examples using the vbRichClient5 ThreadHandler

    Quote Originally Posted by Resurrected View Post
    ...I might be able to split the array into parts each of which gets dealt with by a separate thread. Therefore, I thought, the performance could be boosted.

    I experimented on it and it proved to be not the case. Due to the fact, I guess, that all data transfered between threads, over the cThreadHandler, is copied back and forth, the time cost for copying data well exceeds the time saved by using separate threads. Imagine copy arrays of millions of elements again, again, and again across threads...

    I wish I could make all threads work on a same block data, is it possible?
    Of course...

    To avoid unnecessary allocations (or copying) there's several approaches:

    1) allocate (ReDim) the large Array once (in the Main-Thread)
    1.1) pass only the Pointer to that Array (and its dimensions) into your ThreadClass
    1.2) span a virtual Array over that pointer (using SafeArray-techniques)
    1.3) important is, that from within the thread, you "unbind" the virtually spanned Array again at the end of processing

    2) allocate (ReDim) a separate part of the large Array only once in the ThreadClass (in a useful WorkBuf-Size)
    2.1) instruct the Threads, to each fill their "WorkBuf-Array-Part" (on their own, isolated Thread-Allocation)
    2.1) when a Thread is finished with its part, it passes a Pointer to its WorkBufArray-area back to the MainThread
    2.2) The MainThread then being able (along with additional Infos, where this part belongs) to copy over this part very fast (per CopyMemory) into the large MainArray-Allocation.

    The latter approach is a bit safer to handle, because one wouldn't have to take care of proper "SafeArray-Unbinding" within the threads.

    E.g. I was using something like that (as described in 2) in a Multithreaded MandelBrot-Rendering,
    where the (ScreenPixel) size of the total MandelBrot-area was known - each thread then performing
    MandelBrot-calculations on only a "stripe" of the total area - and then reporting back only
    the pointer of such a "thread-internally filled stripe-buffer" to the MainThread.

    The Mainthread then being able, to do a "Blit to a hDC in the MainThread" directly from that
    passed Pointer (that's possible per StretchDIBits for example).

    So, approach #1 (Spanning of Virtual-Arrays) is the least resource- and communication intensive - but approach #2
    is also useful in some cases (where a kind of copying is involved anyways, as e.g. in a Screen-Blit-Operation).

    To give a clear recommendation for one or the other, I'd need to know what your scenario is...

    Olaf
    Last edited by Schmidt; Aug 21st, 2016 at 03:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width