delphi - TBitmap to TPngImage and Memory usage -


i have array of 11 white tbitmaps (32-bit 512x512 pixles = 1 mb) , want assign them tpngimage array reduce memory usage, expect 1 mb white bitmap become 1.76 kb png , memory usage drop dramatically monitored task manager , difference 0.824 mb why that? , best/fast way lossless compress tbitmaps in memory?

 := 0 10 begin   bitmaps[i] := tbitmap.create;   bitmaps[i].pixelformat := pf32bit;   bitmaps[i].canvas.pen.color := clwhite;   bitmaps[i].setsize(512,512);   bitmaps[i].canvas.rectangle(0,0,512,512); end;

for := 0 10 begin pngs[i] := tpngimage.create; pngs[i].assign(bitmaps[i]); bitmaps[i].free; end;


update

form @bummi research think best thing save pngs in memory stream array, makes difference 9.7 mb.

 := 0 10 begin   png :=  tpngimage.create;   png.assign(bitmaps[i]);   streams[i] := tmemorystream.create;   png.savetostream(streams[i]);   bitmaps[i].free;   png.free; end; 

when released tbitmap released 2 things:

  • memory fastmm4 delphi heap manager
  • hbitmap windows gdi handle

sometimes windows shrink working set if minimize program's windows , restore them back, not granted. re-arranging process memory due relatively small today 10mb difference not slowing down nothing.

read more starting answer @ https://stackoverflow.com/a/14380287/976391

http://fastmm.sourceforge.net/ comes readme , demo how measure memory usage inside process, if makes curios.

but if want reduce ram usage - not allocate it. make 1 tbitmap , assign al pngs it. though again, widows said 10mb not figure care about.


also, user539848 spotted, have 11 bitmaps, not 10. avoid off-by-one errors better not use magical constants use reliable compiler constructs.

for := low(bitmaps) high(bitmaps) begin   bitmaps[i] :=... 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -