Jump to content

Shrinavat

Members
  • Content Count

    63
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Shrinavat


  1. 2 hours ago, Schokohase said:

    How can you speed it up?

    Ok, I get it. That answers my original question, but now I'm curious about my next question.

    How to implement some kind of "image factory", which is constantly running in the background? It must have a variable number of parallel subtasks to create each image. In my opinion, the "pipeline" abstraction is not suitable for this, since it is a sequential conveyor.


  2. 2 hours ago, Schokohase said:

    Again, use BlockingCollection from OTL and build a pipeline

    Why should I use a pipeline? And what about ForkJoin abstraction? Here is a quote from the "Parallel Programming with OmniThreadLibrary" book:

    Quote

    A typical fork/join usage pattern is:
    • Execute multiple subtasks.
    • Wait for subtasks to terminate.
    • Collect subtask results.
    • Use results to compute higher-level result.

    Isn't that for my case (to create multiple different LargeImages in parallel and then merge them into one resulting image)? 


  3. 14 hours ago, Cristian Peța said:

    I think it will be no gain or even worse because LargeImage will not execute anything in parallel.

    After more thinking I agree with you. I will do without multithreading when creating a single LargeImage.

     

    But I have another question. Put my previous code in the BuildLargeBitmap function:

    function BuildLargeBitmap(some parameters): TBitmap32;
    begin
      // creating a large image from tiles
    end;

    I need to create multiple different LargeImages in parallel and then merge them into one resulting image. Schematically, as in the attached image. The number of LargeImages is not constant (!) and can be from 1 to 5. Each LargeImage is created from unrelated databases (there are no problems with competing DB connections). If the number of LargeImage is 1, then ResultImage = LargeImage1. Moreover, this operation of building LargeImages and merging them is repeated many times during the application life cycle. That is, I need to have a some "image factory" that is constantly running in the background. I do not understand how to do this using OmniThreadLibrary abstractions.

    I would be very grateful if someone could help me create a sketch of the code for this task!

    scheme.png


  4. My task is to draw a lot of small images in a certain order on one large one. I'm using TBitmap32 from Graphics32 Library. Since TBitmap32 is a descendant of TThreadPersistent, it inherits its locking mechanism and it may be used in multi-threaded applications.
    Here is how I do it now in the main thread:

    var
      LargeImage: TBitmap32;
    
    procedure BuildLargeBitmap;
    var
      x,y, bx,by: integer;
      AreaRect: TRect;
      tile: TBitmap32;
    begin
      LargeImage.BeginUpdate;
      try
        AreaRect := GetSpecifiedArea;
    
        // small images (tiles) are 256*256 pixels in size
        LargeImage.SetSize(256 * (AreaRect.Right - AreaRect.Left+1), 256 * (AreaRect.Bottom - AreaRect.Top+1));
    
        { loop of drawing tiles on a large bitmap }
        by := 0; // bx,by - coordinates on the bitmap where the tile is drawn (in tiles)
        for y := AreaRect.Top to AreaRect.Bottom do begin
          bx := 0;
          for x := AreaRect.Left to AreaRect.Right do begin
            tile := GetTileFromDB(x, y); // get tile from the database
            if Assigned(tile) then // if tile exists, render it on the large bitmap
              RenderTileToBitmap32(LargeImage, tile, bx*256, by*256);
    
            inc(bx);
          end;
          inc(by);
        end;
    
      finally
        LargeImage.EndUpdate;
      end;
    end;

    I want to use all the power of OmniThreadLibrary and bring this rendering loop to a separate thread(s).
    Which one of the proposed abstractions should I use? ForEach, Fork/Join, Map or something else? Please give me advice and an example applicable to my task.
    Thanks!


  5. Hi,

    How to correctly check if the parent menu item has at least one child item with Checked = True?

    Is it good way?

    function HasCheckedSubItems(AMenuItem: TMenuItem): Boolean;
    var
      i: integer;
    begin
      Result := False;
      for i := 0 to AMenuItem.Count - 1 do
        if AMenuItem.Items[i].Checked then
          Exit(True);
    end

    I'd appreciate any help you can give me. Thank you.

×