CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Form.Invalidate(...)

    Does anyone have any idea which of these is more efficient?

    Code:
    List<Rectangle> rectangles;
    //some code to build the list (up to 56 rectangles)
    
    // (1) is this the quickest?
    foreach (Rectangle rect in rectangles)
      this.Invalidate(rect);
    
    // (2) or is this?
    Region region = new Region();
    
    foreach (Rectangle rect in rectangles)
      region.Union(rect);
    
    this.Invalidate(region);
    OR... is it dependent on too many other factors to make a judgement?

    Incidentally, in my scenario, if I use the region (2) option, then I don't need to build the list of rectangles beforehand, I can just add them to the region as they are created. This is because either the List<Rectangle> or the Region is returned from another function and not actually created in the same routine as in my example above.
    Last edited by rliq; April 7th, 2010 at 07:28 PM.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Form.Invalidate(...)

    Test test test, that is the best way to determine these things. however, If I had to guess, I would assume that option A would be quickest due to the simplicity of handling rectangles as opposed to amorphous regions. Maintaining a collection of rectangles is trivial.

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

Featured