Re: One Thing I Noticed - Line Too Long



"Mike Williams" <mike@xxxxxxxxxxxxxxxxx> wrote in message
news:dk33kk$8ol$1@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Jerry. Yes. I got a few of those "line too long" errors too. I'm not
> sure
> whether it is due to the size of the thread or perhaps a problem with the
> message we were replying to. It went off in the end though, after a bit of
> fiddling around. I don't know where Michael C is getting his information
> from, but he seems to think that a VB Autoredraw picture box has two
> bitmaps
> in memory plus a further bitmap, or "extra space on the Form wasting
> memory"
> as he puts it. That it simply not true. He is wrong on both counts.

Turning on autoredraw keeps a copy of what's on the screen in memory. If you
are drawing a bitmap to the screen and have the bitmap in memory then you
also have another copy of the bitmap in the autoredraw buffer and another
copy in the video cards memory. The video card doesn't matter because it's
using the same amount of memory anyway but you still have 2 copies in your
program's memory.

> Firstly, to deal with his "extra space on the Form wasting memory" remark,
> check out the following. Paste the code into a VB Form containing one
> Picture Box and one Command Button. Compile it to an exe on your desktop
> and
> then minimize or close all windows, so that you can see all of your
> desktop.
> Now run the project and click the button. Check out what is displayed on
> the
> Form. As you will see, the code blits the "non autoredraw" picture box
> device context bitmap to the Form. Check it out and you will see that part
> of the desktop is included in that blit. That is because we used negative
> values for the x and y origin in the picture box hDC. This shows quite
> clearly that the non-autoredraw picture box bitmap is actually a portion
> of
> the already existing full screen bitmap. They are one and the same.

Are you kidding? I honestly thought you understood all of this :-) The
autoredraw buffer has it's copy of the bitmap which has been copied to the
screen. They are not one and the same, they are 2 seperate buffers that
contain the same data.

> Next, to check out his "Autoredraw picture box has two memory bitmaps"
> statement, set your system colour depth to 16 bits per pixel (so as to
> avoid
> any possible confusion between 24 bit and 32 bit) and also use your My
> Computer / Properties / Performance to "disable" Windows virtual memory
> (this will require a restart). Now create a new VB project and place one
> picture box and two command buttons on the Form. Set the Index property of
> the picture box (at design time) to zero. Then paste in the following
> code.
> If you run the program and click Command1 the program will soon stop with
> an
> error to tell you that it is out of string space. Note the number of
> strings
> declared (as displayed in the Form's caption bar). Now run the program
> again, but this time click Command2. This time the program will stop with
> an
> error telling you that it "Can't create an Autoredraw Image". Again, note
> down the number of picture boxes created. The number should be similar to
> the number of strings created in the previous run. If Michael C was
> correct
> then the number of picture boxes created would be about half of the number
> of strings created. But it is not. I think that proves our case as good as
> any discussion might do.

You really don't understand how this works, do you Mike? How could you
seriously tell me I'm "wrong on every count" when you don't understand the
basic way in which autoredraw works?!? How do you think vb does the
autoredrawing? It creates a bitmap in memory the size of the form and keeps
it there. When the form needs repainting it copies the bitmap to the screen.

Your test actually proves me write on 2 counts. Although it's fairly
ambigous, it could be running out of GDI resources. First, I would predict
the number to be similar. Autoredraw keeps a bitmap in memory for every
autoredraw surface you create. If you have the bitmap in memory that you are
drawing then you have that copy + another in the autoredaw buffer which is 2
copies but in your case you'd only have the one bitmap in the autoredraw
buffer. Second, didn't it ring alarm bells in your head that autoredraw is
inefficient when you got the error at less than 100 pictureboxes? With
autoredraw turned off I could create the full 5000 pictureboxes.

Try this test. Put a command button on a form and add this code. You will
clearly see in task manager that each time you click the button another
chunk of memory is used, approx 7.5MB per form on my machine. If that
doesn't clear it up let me know what you don't understand and I'll explain
further.

Michael

Option Explicit

Private Sub Command1_Click()
Set Form1 = Nothing
Form1.Show
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
Me.Line (0, 0)-(100, 100)
End Sub



.


Loading