CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    10

    Ways Around GDI Resource Limits?

    Hello All,

    I have created some pretty graphic intensive controls.. They all use CBitmap for holding their
    images..I am having a problem with this because
    it eats up the GDI resources.. Heres my question/s
    a. Is there a way to store a Bitmap(in memory) that I can draw to the screen that does not take up GDI resources..
    b. Is there any way to expand the available GDI resources in Windows95/98?

    Thanks for any help!

    Regards

    David Swigger

    Please don't tell me it's impossible. That just means I have to proove it...

  2. #2
    Join Date
    Apr 1999
    Posts
    21

    Re: Ways Around GDI Resource Limits?

    To solve the resources leaking, you should delete the GDI object after you finish to used it. Take a look to

    CGdiObject:eleteObject()

    or

    BOOL DeleteObject(
    HGDIOBJ hObject // handle to graphic object
    );

    Good luck

    Fabian


  3. #3
    Join Date
    Apr 1999
    Posts
    10

    Re: Not a GDI leak...

    Sorry, Im not talking about memory or GDI leaks,
    Im saying that the amount of Objects that I am
    using is taking up too much of the GDI..Im using
    a ton of CBitmaps..
    Sorry for the Confusion..

    Regards

    David

    Please don't tell me it's impossible. That just means I have to proove it...

  4. #4
    Join Date
    Apr 1999
    Posts
    1

    Re: Ways Around GDI Resource Limits?

    There are two ways to approach this problem.

    The easiest way, is to NOT keep all of your CBitmaps in memory. Dispose of them after they have been drawn, reload them as neccessary. You can reduce any performace loss by creating a type of caching mechanism to keep frequently drawn CBitmaps in memory.

    The harder method would be to NOT use CBitmaps at all, instead using DIB's. Using DIB's will not use GDI, since a DIB is using memory from HEAP. With DIB's you will be responsible for making sure that the DIB color depth is less than or equal to the screen's color depth (for Blting performace) as well as color mapping performance issues. (Read Nigel Thompson's book on Animation Techniques in Win32 (MSPRESS)). Be sure to read up on 'identity palettes' to make sure your 256 color mode performance is optimal.

    The first technique is a quicker fix, but if done right the second method is much better.

    Regards,
    Todd


  5. #5
    Join Date
    Apr 1999
    Posts
    2

    Re: Not a GDI leak...

    Why don't you store your images in an image list?


  6. #6
    Guest

    Re: Not a GDI leak...

    There are a few things you can do...but it will be at the expense of performance. Not keeping all of the bitmaps in memory was a good suggestion - try it.

    Also, encapsulate resources in braaces to force them in and out of scope. This is very helpful in looping code when a function is called many times.

    Example:

    void YourClass:raw(CDC* pDC)
    {
    {
    CDC tempDC(this);
    DoABunchOfStuff( &tempDC);
    pDC->BitBlt( tempDC, blah, blah );
    } //close this brace if you no longer need tempDC
    //since tempDC went out of scope it is not hogging
    //up resources%3

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