I am working on a program that will have many DIB bitmaps (created by CreateDIBSection
) and will have to draw a lot of text on them using Win API.
In order to draw on the bitmap, Windows needs device context, created by CreateCompatibleDC
.
And now here are two approaches:
I can create the DC once per bitmap, using it for drawing and delete it when freeing the bitmap.
Or I can create DC only when I need to draw to the bitmap, call the draw functions and delete the DC.
What is the better approach? I prefer the first, because of less calls - this will make my code much smaller and also a little bit faster.
But isn't it too expensive to hold a long living DC for every bitmap?
Edit1: The application is actually a GUI toolkit library that can be used in different and unpredictable way in the future, so I need a well balanced decision with maximal possible performance and minimal system resource usage.