Page 1 of 1
[PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 9:57 am
by dige
For a project with pictures, I need the ability to store them in the cache (memory). What struck me, that, these are limited independently of free memory.
Tested with PB 4.30...5.11 x32Bit @ Win7 x86 4GB RAM, Win7 x64 8GB RAM
Code stopps hier at 9988 images
ProcessExplorer tells me:
- 9.999 GDI Handles
- Working Memory 47MB
- Free Memory: 2.3 GB
So, that means, there are only 9.999 GDI handles allowed?
Code: Select all
OpenWindow(0, 0, 0, 600, 400, "")
NewList Img.l()
For a = 1 To 20000
success = #Null
If AddElement(Img())
ImgID = CreateImage(#PB_Any, 1, 1)
Img() = ImgID
EndIf
If ImgID And IsImage(ImgID)
success = 1
EndIf
If success <> 1
ForEach Img()
FreeImage(Img())
Next
MessageRequester( "Error", Str(a))
End
EndIf
Next
MessageRequester( "No error", ":-)")
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 10:10 am
by STARGĂ…TE
Look here:
GDI Objects
There is a theoretical limit of 65,536 GDI handles per session. [...] There is also a default per-process limit of GDI handles. To change this limit, set the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota
Value on my system: GDIProcessHandleQuota = 10,000
So i think no bug.
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 11:29 am
by Rings
yes, its a windows (OS) restriction, no pb bug .
Topic moved....
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 12:45 pm
by dige
How can you determine the number of GDI handles via API, used by my program?
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 12:57 pm
by Rings
read the registry key
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 1:00 pm
by LuCiFeR[SD]
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 1:00 pm
by dige
@Rings: ? I need to know, how many GDI handles use my program...
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 1:01 pm
by dige
Thx!

Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Tue Jun 04, 2013 1:09 pm
by dige
Code: Select all
Procedure GDI_CountHandles()
#GR_GDIOBJECTS = 0
#GR_USEROBJECTS = 1
ProcedureReturn GetGuiResources_( GetCurrentProcess_(), #GR_GDIOBJECTS )
EndProcedure
GDI_CountHandles()
Re: [PB5.11 x86] Number of images (gdi handles) limited
Posted: Fri Jun 07, 2013 6:11 pm
by codeprof
You could save the images in an array and draw them by yourself with SetDIBitsToDevice.
Code: Select all
;Autor: codeprof
;Licence: Public Domain
Structure BITMAPINFO_RGB
bmiHeader.BITMAPINFOHEADER
rgbRed.l
rgbGreen.l
rgbBlue.l
EndStructure
Procedure DrawArray(hDC,width,height,*pointer)
Protected bmi.BITMAPINFO_RGB
bmi\bmiHeader\biSize =SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biWidth = Width
bmi\bmiHeader\biHeight =-Height
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biCompression = #BI_bitfields
bmi\rgbBlue = $00FF0000
bmi\rgbGreen = $0000FF00
bmi\rgbRed = $000000FF
ProcedureReturn SetDIBitsToDevice_(hDC,0,0,Width,Height,0,0,0,Height,*pointer,@bmi,#DIB_RGB_COLORS)
EndProcedure
Dim Picture(255,255)
For x=0 To 255
For y=0 To 255
Picture(y,x)=RGB(x,x,x) ;x and y are swapped here
Next
Next
OpenWindow(1,0,0,1000,500,"DrawArray test",#PB_Window_SystemMenu)
Repeat
hDC = StartDrawing(WindowOutput(1))
DrawArray(hDC,256,256,@Picture(0,0))
StopDrawing()
Until WindowEvent()=#PB_Event_CloseWindow