LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory problem with bitmaps

A strange bug ?

I generate an arrow of 1000x1000 pixels with random data. I create a new bitmap with these data and display it in a canvas.
When I look the process memory used (from windows tasks under Windows 2000),
I notice that the memory used will decrease if I put a MessagePopup between the NewBitmap and the CanvasDrawBitmap.
The project joined with this e-mail illustrates this.

Thank you for your answer

best regards


ArnO
0 Kudos
Message 1 of 8
(4,429 Views)
Hello, Arno

The short answer to your question is that the Memory Usage shown by the Task Manager is not a good indicator of how much memory a CVI application is using.

The long answer is the following: for efficiency purposes, the CVI run-time engine manages the memory used by a CVI app. This memory includes, but is not limited to, calls to malloc. Part of this memory management involves allocating memory from the system in large chunks, then doling out blocks of this memory to the application as is needed. Eventually, in specific instances, these memory chunks are returned to the system whenever it is optimal to do so. The consequence of this, is that when you track the memory usage of your application using the Task Manager, you only see the memory tha
t CVI allocates from the operating system. Some of this memory is really "free" as far as your aplication is concerned.

What is happening with your application is that the function NewBitmap uses a large amount of memory to create a bitmap of 1000x1000 pixels. Upon exiting the function some of this memory is no longer needed and is freed (part of it remains allocated until you call DiscardBitmap). However, in the normal case CVI will not release this newly freed memory completely, and will instead use it to parcel out any future memory requirements of your application. Therefore, you don't see the memory disappear form the Task Manager. On the other hand, when you called MessagePopup, you accidentally stumbled into one of those instances where CVI returns to the OS memory that is not being used. This happens whenever any panel is discarded, including the MessagePopup panel.

In the end, the call to MessagePopup has no effect on the true memory usage of your application.

Luis Go
mes
NI
Message 2 of 8
(4,429 Views)
Thank you for this clear answer.

I had ask for a bug on displaying bitmap into canvas under windows 2000. The document ID for this CAR is 2GADTO7Z. Is there any news on this ?

best regards

ArnO
0 Kudos
Message 3 of 8
(4,429 Views)
We haven't investigated that issue yet. It will probably still be a few weeks before we get to it. I'll keep you informed.

- luis
0 Kudos
Message 4 of 8
(4,429 Views)
Just to let NI know, I'm having a similar problem. I'm using a PCI-1407 Video Aquisition card, CVI 5.5, and Windows 2000 to grab a 640x480 image. I create a bitmap of the image and then use the function DrawCanvasBitmap to show the bitmap (greyscale) to the canvas control. When the canvas control height/width is set to 640x480 it looks good. but if the canvas control is scaled, 320x240 for example, the greyscale colors get messed up. The bug looks to be in DrawCanvasBitmap with Windows 2000. The same exact code, executable, works fine under Windows 98/Me.
0 Kudos
Message 5 of 8
(4,429 Views)
Arno, hamburger:

Just wanted to let you know that we've recently found the root of the problem that the two of you ran into. Basically, the source of the problem can be traced to a Microsoft bug that occurred in Windows 9x:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q138105

Unfortunately, CVI's workaround for the bug back then was now causing your problem to appear in 2000 & XP.

The fix will be in the next version of CVI. If you have some urgency in having this problem solved, you have two options:

1. You can sign up for the beta program of the next version (www.ni.com/beta). This will reduce your wait time substantially.

2. There is a workaround that you can try now, but it is a bit cumbersom
e, and the drawing time for the bitmap will be somewhat slower. The workaround consists of converting the bitmap into a transparent bitmap, which will force it into a different drawing algorithm. The bitmap doesn't actualy have to be transparent: you can specify a mask where every bit is set to 1 (check out the documentation for GetBitmapData / SetBitmapData).

Hope this helps. Let me know if you have any other question.

Luis Gomes
NI
0 Kudos
Message 6 of 8
(4,429 Views)
Does this mean the bug is still present in the latest LabWindows/CVI, Version 6.0?
0 Kudos
Message 7 of 8
(4,429 Views)
Yes it does. 6.0 was released about a year ago, and we've just now fixed the bug, so the fix will show up in the first version following 6.0

- luis
0 Kudos
Message 8 of 8
(4,429 Views)