LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to allocate more memory to bitmaps

Hi,
 
I am wondering if it is possible, and how to allocate more physical memory to CVI bitmaps.
My problem is:
after creating approx 22 bitmaps (size = 1275*960, 24bit colour), I get an out of memory error.
My system is winXP, 1GB RAM. Windows reports that there is approx 500MB free before I start, and approx 355MB free when I get the error.
 
Discarding the earlier bitmaps is not a viable solution as my bitmaps are quite complex and generating them takes a few seconds.
My final app needs to switch between them much faster than they can be generated.
I need to make and store about 50 or 60 of these bitmaps, which should require about 300MB of RAM.
 
Is it possible to increase the memory allocation?
Thanks in advance
0 Kudos
Message 1 of 7
(3,851 Views)
Sorry, should have mentioned that my final app needs to be on a 1600*1200 screen, hence the 300MB figure.
0 Kudos
Message 2 of 7
(3,843 Views)
What functions are you using to allocate (AllocBitmapData, AllocBitmapDataEx, etc)? Also, would it be possible to post a small example (maybe just grabbing the same image over and over again) so I can easily see the same behavior?

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 3 of 7
(3,830 Views)

Hi Brandon,

I'm generating the bitmaps using the NewBitmap funtion. They are to be used for visual testing, and need to be cycled fast enough to effectivley create an animation. The  image set need to be re-created on an arbirtary basis several times in the app as the test progresses through it's phases. After each phase, all exsisting bitmapIDs are discarded before creating new ones.

As I understand it, the functions you mentioned, AllocBitmapData& AllocBitmapDataEx would only be used when taking data from an exsisting bitmap.

Also, I did a few quick calculations of memory usage based on what the windows task manager reports. Reported change in memory usage was almost double what I calculated using x*y*pixelDepth. Does that sound right?

code snippet: 

for (i=0;i<lastFrame;i++)
 {
  if (animBmp[i] != 0)
   DiscardBitmap (animBmp[i]);
   
  animBmp[i] = MakeBitmapTypeA (canvasSizeX, canvasSizeY, shapeFactor*i+PPC, /*...PORTION OMMITTED...*/);
 }
   

int MakeBitmapTypeA (int canvasSizeX, int canvasSizeY, /*...PORTION OMMITTED...*/)
{
/*...PORTION OMMITTED...*/
 for (absX=halfCanvasX;absX<canvasSizeX;absX++)
 {
  /*...PORTION OMMITTED...*/
  for (absY=halfCanvasY;absY<canvasSizeY;absY++)
  {
   /*...PORTION OMMITTED...*/

/*All quadrants are identical, so generate one and mirror it into the other three*/
   arrY = canvasSizeX*3*absY;
   arrYinv = canvasSizeX*3*(canvasSizeY-absY-1);
   baseIndex_SE = arrY  + arrX;  //+x,+y
   baseIndex_NE = arrYinv + arrX;  //+x,-y
   baseIndex_NW = arrYinv + arrXinv; //-x,-y
   baseIndex_SW = arrY  + arrXinv; //-x,+y

   arrPixels[baseIndex_SE]  = arrPixels[baseIndex_NE] =
    arrPixels[baseIndex_NW]  = arrPixels[baseIndex_SW] = (colour&0xFF0000)>>16; //rr
   arrPixels[baseIndex_SE+1] = arrPixels[baseIndex_NE+1] =
    arrPixels[baseIndex_NW+1] = arrPixels[baseIndex_SW+1] = (colour&0xFF00)>>8; //gg
   arrPixels[baseIndex_SE+2] = arrPixels[baseIndex_NE+2] =
    arrPixels[baseIndex_NW+2] = arrPixels[baseIndex_SW+2] = (colour&0xFF);  //bb
  }
 }
 NewBitmap (canvasSizeX*3, 24, canvasSizeX, canvasSizeY, NULL, arrPixels, NULL, &bitmap);
//free up memory allocated to dynamic arrays
free (arrPixels);
 return bitmap;
}

0 Kudos
Message 4 of 7
(3,822 Views)
Diz,

First, the reason double the amount of memory is being used is because you create a NewBitmap in your subroutine (MakeBitmapTypeA) and the return that bitmap (making a copy of it). If you never release that first bitmap, it stays in memory and you will always have 2 copies of that bitmap.

Second, it seems this should be easy to reproduce by putting the NewBitmap function in a for loop, which I attempted to try to do, however I am not sure what you are putting for the bit parameter. Could you possibly give me a snippet of code to replicate what you are doing here so I can further try to reproduce this error?

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 5 of 7
(3,801 Views)
Hi Brandon,
 
For IP reasons I cant send the actual code, so I've made a demo project as an example.
To reproduce the error, the canvas panel must be maximised before generating the bitmaps
 
I havent tried it yet, but a way around this problem could be to store the 'bitmaps' before they are processed by NewBitmap - as pixel value arrays.
Unless the memory issue is caused by a global memory use restriction? - Does such a restriction exsist?
 
 
WRT to bitmap use and memory, I'm not exactly sure what you mean when you say I am making a copy of the bitmap? Given the bitmap ID is an integer, I could understand how that might waste memory equal to one integer, but not the whole bitmap?
If I create a bitmap in a function, can't that handle (and hence memory) be discarded at any point during program execution, by any function?
Anway, I changed the code to put the bitmap handle in a pointer given when calling the function, this seems to use less memory, but still more than x*y*depth.
 
Cheers.
0 Kudos
Message 6 of 7
(3,792 Views)
Diz,

I've passed this on to R&D to look into this and determine what is going on. Also, I'm not sure if you're using Task Manager to view memory usage, but since the CVI Runtime Engine handles memory. Because of this, Windows Task Manager is not a good way to determine memory usage or allocation.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 7 of 7
(3,769 Views)