Recent

Author Topic: EOutOfMemory when creating 10000 BgraBitmap objects  (Read 4084 times)

MaartenJB

  • Full Member
  • ***
  • Posts: 101
EOutOfMemory when creating 10000 BgraBitmap objects
« on: November 23, 2021, 03:35:45 pm »
Hi,

I get an "EOutOfMemory" "TBGRAWinBitmap.ReallocBitmap: Windows error 87" message when I create 10000 BgraBitmap objects. Is there something that I'm missing here? I do not get this error when using a standard TBitmap.

Best regards,

Maarten

Code: Pascal  [Select][+][-]
  1. var
  2.   Index : Integer;
  3.   BitmapArray : Array of TBGRABitmap;
  4. begin
  5.   SetLength(BitmapArray, 10000);
  6.  
  7.   for Index :=Low(BitmapArray) to High(BitmapArray)
  8.   do begin
  9.     BitmapArray[Index] := TBgraBitmap.Create(1,1);
  10.   end;
  11. end;  


Version: Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64
« Last Edit: November 23, 2021, 04:28:27 pm by MaartenJB »

MaartenJB

  • Full Member
  • ***
  • Posts: 101
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #1 on: November 23, 2021, 03:49:24 pm »
Hmm, TBGRANoGUIBitmap doesnt raise this error. gonna see if I can use this one

Zvoni

  • Hero Member
  • *****
  • Posts: 857
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #2 on: November 23, 2021, 04:12:52 pm »
??
Writeln(SizeOf(TBGRABitmap));
and then multiply it with 10,000
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

winni

  • Hero Member
  • *****
  • Posts: 2871
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #3 on: November 23, 2021, 04:17:20 pm »
Hi!

No error with Linux64.

Winni

MaartenJB

  • Full Member
  • ***
  • Posts: 101
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #4 on: November 23, 2021, 04:24:50 pm »
??
Writeln(SizeOf(TBGRABitmap));
and then multiply it with 10,000

If I create the tbgrabitmap without specifying a canvas size, the message does not appear. (It does as soon as you set it to size though)
So I don't see how the above would help me. I'm not actually running out of memory.

It's just raised from here:
Code: Pascal  [Select][+][-]
  1. procedure TBGRAWinBitmap.ReallocData;


Hi!

No error with Linux64.

Winni

It's windows specific I guess.

Bart

  • Hero Member
  • *****
  • Posts: 4611
    • Bart en Mariska's Webstek
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #5 on: November 23, 2021, 04:29:01 pm »
Leaking resource handles maybe?

Bart

winni

  • Hero Member
  • *****
  • Posts: 2871
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #6 on: November 23, 2021, 04:30:13 pm »
Hi!

I wont believe it! Like 30 years ago: still a problem with the maximum GDI-Handles. Seems that some Windows-problems never change:


https://stackoverflow.com/questions/38612364/how-to-increase-the-maximum-amount-of-gdi-object-for-windows-10

Winni

MaartenJB

  • Full Member
  • ***
  • Posts: 101
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #7 on: November 23, 2021, 07:56:04 pm »
Hi!

I wont believe it! Like 30 years ago: still a problem with the maximum GDI-Handles. Seems that some Windows-problems never change:


https://stackoverflow.com/questions/38612364/how-to-increase-the-maximum-amount-of-gdi-object-for-windows-10

Winni

Thx Winni,

I didn't know it worked that way, I'll reconsider my approach.

circular

  • Hero Member
  • *****
  • Posts: 3756
    • Personal webpage
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #8 on: November 27, 2021, 07:49:17 pm »
You could use TBGRALCLBitmap instead from BGRALCLBitmap unit. It may not display correctly or as quickly on Canvas, but at least, it won't take GDI handles. At least as long as you don't access the Bitmap property I guess.
Conscience is the debugger of the mind

MaartenJB

  • Full Member
  • ***
  • Posts: 101
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #9 on: November 29, 2021, 03:11:16 pm »
Thanks Circular,

My application needs raw speed, so I've adjusted my approach so I don't run into this problem. I now use a single TBgraBitmap and use segments.

It's nice to have "TBGRALCLBitmap" in my toolbelt though.


circular

  • Hero Member
  • *****
  • Posts: 3756
    • Personal webpage
Re: EOutOfMemory when creating 10000 BgraBitmap objects
« Reply #10 on: December 03, 2021, 08:16:22 am »
You're welcome.  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018