[PB5.11 x86] Number of images (gdi handles) limited

Windows specific forum
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

[PB5.11 x86] Number of images (gdi handles) limited

Post 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", ":-)")
"Daddy, I'll run faster, then it is not so far..."
User avatar
STARGÅTE
Addict
Addict
Posts: 2261
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by Rings »

yes, its a windows (OS) restriction, no pb bug .

Topic moved....
SPAMINATOR NR.1
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by dige »

How can you determine the number of GDI handles via API, used by my program?
"Daddy, I'll run faster, then it is not so far..."
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by Rings »

read the registry key
SPAMINATOR NR.1
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by LuCiFeR[SD] »

dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by dige »

@Rings: ? I need to know, how many GDI handles use my program...
"Daddy, I'll run faster, then it is not so far..."
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by dige »

LuCiFeR[SD] wrote:MSDN
Thx! :-)
"Daddy, I'll run faster, then it is not so far..."
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post by dige »

Code: Select all

Procedure GDI_CountHandles()
  #GR_GDIOBJECTS = 0
  #GR_USEROBJECTS = 1
  
  ProcedureReturn GetGuiResources_( GetCurrentProcess_(), #GR_GDIOBJECTS )
EndProcedure

GDI_CountHandles()
"Daddy, I'll run faster, then it is not so far..."
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: [PB5.11 x86] Number of images (gdi handles) limited

Post 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
Post Reply