 |
Resource DLL
In order to fully understand the impact of the new
resource dll, we first need to understand how Window's
creates and manages memory with respect to drawing.
To put
things simply, when you want to draw in Windows (i.e.
creating the control's image), you do so on a device
context (DC). You can think of this as a canvas an
artist would use to paint a picture. In Windows,
these canvases do not come for free. The price for
each canvas is measured in a specific amount of memory.
In Windows, these canvases are known as GDI objects.
Windows 2000 and above, handle the GDI object memory
differently than older Windows operating systems, and
therefore can have alot more of these objects loaded.
We all remember the days in Windows98 where all of a
sudden you get a low memory (or low resources) alert
regardless of the amount of actual RAM we have.
This is because we have exceeded the allowed resources
or amount of GDI objects. For older systems, there
is no way around this. You simply have to plan
your project more carefully keeping in mind the number
of images. To see the effects of GDI on system
resources, try this simple test:
Open a new project and add a single ImageList control to
the form. Now start adding icons or other images
to the ImageList. If your running an older system,
go to the control panel and view the system. You
will notice that the more images you add to this single
control, the lower your system resources will go until
you reach the point where you can no longer display the
form. For newer systems, such as XP, press
ctrl-alt-delete to display the Windows Task Manager.
Click the Processes tab. Click the View menu, then
"Select Columns", and check the "GDI Objects" option.
Find your app (i.e. VB6.EXE) in the task manager, and
look over to the GDI Objects column. This will
show you the actual number of GDI objects current in
memory. This is also a good way to plan your app,
and see the total number of objects you can have before
the system warns of low resources.
Essentially, what XPSuite does is provide a set of
controls which act like Windows XP regardless of the
operating system. However, even though the
controls act like XP, when running in an older system,
they are not, and must conform to the limits of that
operating system. So what does all this mean when
it comes to the controls? Each control requires a
certain number of GDI objects, or canvases, to be held
by the control during the life of the control.
Therefore the number of controls we have loaded into
memory at any given time will determine the total number
of GDI objects, and therefore the total amount of
resources or memory required.
Previous
versions of the XPSuite controls created and managed
their own GDI objects. If for example you have a
form with 50 XPButtons, and each button requiring 2 GDI
objects, then a total of 100 objects would be required
whenever that form is loaded into memory. If all
the buttons had the same VisualStyle and Theme, then
this would seem unnecessary, since for all intensive
purposes, the buttons use the same image, with only the
size of the button changing. Common sense would
say why can't we just use the same canvas to apply to
all buttons?
XPSuite 4.0 incorporates a new resource dll specifically
designed to centrally handle creating the required GDI
objects used by the controls during the drawing process.
In the above button example, using the new resource dll,
the first button to initialize, calls the resource dll,
requesting the GDI object for it's specific VisualStyle
and Theme. The resource dll creates the object
(GDI object). Instead of passing the object back
to the button, the dll passes the object's handle back
to the button. The button uses this object to draw
itself. The important thing here to note, is that
the button is not holding the object. Instead it
only keeps a handle to the object, which is actually
held by the dll. When the second button on the
form initializes, it too requests the required GDI
object from the resource dll. However, since the
resource dll already created an object for the button
class using the specified VisualStyle and Theme, instead
of creating a new object, it simply passes the previous
object handle to the new button. This continues
for all 50 buttons. So after the form has loaded
with the 50 buttons, a total of 2 GDI objects were
created instead of 100.
Two main advantages are realized by incorporating the
new dll. First, a dramatic reduction in resource
consumption. Second, a significant improvement in
the control's loading performance, since
each control
no longer has to create it's DC or canvas.
|
 |