Click here to Skip to main content
15,886,835 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Generalpaint application question Pin
lfsong30-Apr-03 0:41
lfsong30-Apr-03 0:41 
GeneralRe: paint application question Pin
J. Dunlap30-Apr-03 8:31
J. Dunlap30-Apr-03 8:31 
GeneralRe: paint application question Pin
lfsong1-May-03 17:55
lfsong1-May-03 17:55 
GeneralRe: paint application question Pin
James T. Johnson1-May-03 18:06
James T. Johnson1-May-03 18:06 
GeneralRe: paint application question Pin
lfsong2-May-03 5:30
lfsong2-May-03 5:30 
GeneralRe: paint application question Pin
James T. Johnson2-May-03 14:57
James T. Johnson2-May-03 14:57 
GeneralRe: paint application question Pin
lfsong2-May-03 19:03
lfsong2-May-03 19:03 
GeneralRe: paint application question Pin
James T. Johnson2-May-03 23:00
James T. Johnson2-May-03 23:00 
LynnSong wrote:
it start up with a memory use of around 14mb(is .NET application upon CLR alway takes that much memory???),

Yes, this memory is used for a couple things:

Number one is the Garbage Collector (GC), when you start your application the Framework allocates a largish chunk of memory which it uses when you create new objects.

More memory used by the framework itself, in a basic Windows Forms application you are loading at least 3 assemblies no matter what is actually on the form.

mscorlib - houses the most basic classes of the framework
System.Xml - used to parse the application configuration files as well as the computer/user configuration files.
System.Drawing - as the name suggests the classes used for drawing are located here
and lastly: System.Windows.Forms - houses the Windows Forms classes

Looking at the file sizes of those dlls comes up to 5.42MB and that isn't including the various libraries used by the framework that make it all happen (fusion.dll, mscorwks.dll/mscorsvr.dll, mscorjit.dll, plus many others).

LynnSong wrote:
when enlarge to full screen(1400x1050), the memory use rises to about 15mb much

I don't think there is much you can do about this, 1400x1050 at 24bit color comes out at 4,410,000 bytes, if it is 32bit color then you're talking 5,880,000 bytes (approx. 4.2 and 5.6MB respectively).

What you can do is to take advantage of the IDisposable pattern when you can, all/nearly all of the System.Drawing classes offer it so you can free up valuable system resources ASAP.

C# offers a handy keyword which wraps IDisposable so if you need to make use of a Brush or a Bitmap within a single method you can use it and dispose of it easily.

For instance, if you need to draw something to your bitmap (using made up variables of course Smile | :) )

using(Brush brush = new SolidBrush(canvas.ForeColor))
using(Pen pen = new SolidPen(brush, canvas.PenWidth))
using(Graphics g = Graphics.FromBitmap(bitmaps[canvas.CurrentLayer]))
{
  g.DrawLine(pen, lastPoint, currentPoint);
}
// if an exception is thrown within the block
// or when execution has exited the block
// brush, pen, and g will all have Dispose called on them
// giving the system resources back to the system
But what about the GC you may ask?

The GC works well, but you never know exactly when the GC will do its work so when you are dealing with a scarce resource such as system handles or database connections you are far better off doing your work and returning those handles/connections as soon as possible.

LynnSong wrote:
How is the underlying BitBlt you've mentioned worked underlying?

At the heart of GDI+ (System.Drawing stuff) and the .NET framework you still have Windows running it all so you can count on most things you doing going to the basic levels at some point in time.

In this case GDI+ sits on top of the basic routines in Windows for drawing, GDI. So when you make calls into GDI+ at some point in time it is probably going to hit GDI code.

In this case when you want to draw one bitmap onto another the GDI routine is called BitBlt. BitBlt's function is to take pixels from one bitmap and transfer them to another, but in order to do that it may have to do some math wizardry on the source pixels in order to get it into the same format as the destination pixels. For instance if the source bitmap was a 16-bit color image and the destination image 24-bit color it couldn't just copy the memory from the source and place it in the destination, it would need to convert the memory to account for the different color depth.

One way to speed up the call to BitBlt is to make sure the two bitmaps are 'compatible' so BitBlt can just copy pixels rather than having to convert the pixels one bitmap to another format before it can copy. This is what .NET does when you enable double-buffering; it makes sure the bitmap representing the screen and the bitmap representing the offscreen buffer are compatible.

Hope that makes sense, my explainations seem is rather bad today.

James

"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation

GeneralRe: paint application question Pin
lfsong4-May-03 18:46
lfsong4-May-03 18:46 
GeneralRe: paint application question Pin
J. Dunlap4-May-03 18:57
J. Dunlap4-May-03 18:57 
GeneralRe: paint application question Pin
lfsong4-May-03 22:52
lfsong4-May-03 22:52 
GeneralRe: paint application question Pin
James T. Johnson4-May-03 19:05
James T. Johnson4-May-03 19:05 
GeneralRe: paint application question Pin
J. Dunlap4-May-03 19:36
J. Dunlap4-May-03 19:36 
GeneralRe: paint application question Pin
James T. Johnson4-May-03 20:24
James T. Johnson4-May-03 20:24 
GeneralRe: paint application question Pin
J. Dunlap4-May-03 20:29
J. Dunlap4-May-03 20:29 
GeneralRe: paint application question Pin
lfsong4-May-03 23:36
lfsong4-May-03 23:36 
GeneralRe: paint application question Pin
James T. Johnson5-May-03 1:01
James T. Johnson5-May-03 1:01 
QuestionAm I running as a native image? Pin
solidstore29-Apr-03 1:20
solidstore29-Apr-03 1:20 
AnswerRe: Am I running as a native image? Pin
Stephane Rodriguez.29-Apr-03 2:18
Stephane Rodriguez.29-Apr-03 2:18 
GeneralLow level network application Pin
Andrei Matei28-Apr-03 22:29
Andrei Matei28-Apr-03 22:29 
GeneralRe: Low level network application Pin
Andy Davey29-Apr-03 16:16
Andy Davey29-Apr-03 16:16 
Generalcall to the main thread Pin
OmegaSupreme28-Apr-03 15:59
OmegaSupreme28-Apr-03 15:59 
GeneralRe: call to the main thread Pin
Andy Davey28-Apr-03 16:24
Andy Davey28-Apr-03 16:24 
GeneralRe: call to the main thread Pin
OmegaSupreme28-Apr-03 16:54
OmegaSupreme28-Apr-03 16:54 
GeneralRe: call to the main thread Pin
david.minor3-May-03 18:51
david.minor3-May-03 18:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.