Unloadbmp

Geef hier je beste Liberty BASIC tips door. (Hier geen hulp vragen)

Moderators: anthonio, Abcott

Unloadbmp

Berichtdoor glpape » zo mei 06, 2012 1:08 am

Als je een bitmap inlaadt via API's laad je een object in (een bitmap is een object, net als een pen, een brush, een font, en zo nog een paar) en objects nemen werkgeheugen. Zodra je ze niet meer nodig hebt gooi je ze daarom weg met de "DeleteObject" functie.
Hoe zit dat in Liberty BASIC als je meerdere bitmaps inlaadt via <getbmp>, met dezelfde bmpName? Blijven die allemaal hangen in het geheugen of worden ze vanzelf weggegooid met een volgende <getbmp>? <getbmp> is iets van Lbty en heeft geen direct equivalent in de API's.
Ik probeer het uit in de volgende code :

Code: Selecteer alles
REM   Shows memory usage with  <getbmp>  and after  <unloadbmp> .

GoSub [SetUpWdws]

open "" for graphics_nsb as #G
#G "trapclose [qq]"
#G "backcolor yellow; color green; fill yellow; flush"
#G "font Courier_New 300; down"
print cr$(3); "  Memory Status : "; cr$(2)
GoSub [MemStatus]

for n = 1 to 25
  n$ = str$(n)
  #G "place 75 "; DH-(DH*0.4); ";\"; n$
  #G "flush Seg1"
  #G "getbmp aa 0 0 "; DW; " "; DH
     if n<4 then bmpsave "aa", "aatmp.bmp"
  Call Pause 150
#G "delsegment Seg1"
next n
#G "redraw"
print cr$(3); "  After getbmp x25, same bmpName :"; cr$(2)
GoSub [MemStatus]

for n = 1 to 25
  n$ = str$(n)
  #G "place 75 "; DH-(DH*0.4); ";\"; n$
  #G "flush"
  #G "getbmp ab"; n; " 0 0 "; DW; " "; DH
     if n<4 then bmpsave "ab";n, "abtmp";n;".bmp"
  Call Pause 150
next n
print cr$(3); "  And with different bmpName's :"; cr$(2)
GoSub [MemStatus]

unloadbmp "aa"
for n = 1 to 25
  unloadbmp "ab"; n
next n
print cr$(3); "  And after unloadbmp :"; cr$(2)
GoSub [MemStatus]

wait
[qq]
calldll #user32, "PostMessageA", hmain as ulong, _
        _WM_CLOSE as long, 0 as long, 0 as long, rtn as void
close #G  :  end

'  * * * * * * * * * * * * *   GoSubs   * * * * * * * * * * * * * * * * * * * * * * * * * * *

[SetUpWdws]
calldll #user32, "GetActiveWindow", hmain as ulong
DW = DisplayWidth  :  DH = DisplayHeight
x = DW - 444  :  cy = DH - 111
calldll #user32, "SetWindowPos", hmain as ulong, -1 as long, _
        x as long, 44 as long, 333 as long, cy as long, 0 as long, rtn as long
DW = DisplayWidth  :  DH = DisplayHeight
Call SetWdw 0, 0, DW, DH
Return

[MemStatus]
struct M, dwLength as long, _
       MemLoad as long, _        ' contains percentage memory used
       TPh as long, _            ' total amount of physical memory
       APh as long, _            ' available amount of physical memory
       TPg as long, _            ' TotalPageFile - total amount of memory in swap file
       APg as long, _            ' available amount of memory in swap file
       TV as long, _             ' total amount of virtual memory
       AV as long                ' available amount of virtual memory
calldll #kernel32, "GlobalMemoryStatus", M as struct, rtn as long
totmem   = int(M.TPh.struct/1000)
avlblmem = int(M.APh.struct/1000)
usedmem  = totmem - avlblmem
print "  total " ,ul$(-9, 0, totmem); " kB"
print "  available " ,ul$(-9, 0, avlblmem); " kB"
print "  used " ,ul$(-9, 0, usedmem); " kB"
Return


'  * * * * * * * * * * * * *  Subs & Functions  * * * * * * * * * * * * * * * * * * * * * * *


Sub SetWdw a,b,c,d                          ' sets ULX, etc
UpperLeftX = a
UpperLeftY = b
WindowWidth = c
WindowHeight = d
End Sub

Sub Pause pp                                ' pause in milliseconds
tt = time$("ms") : dd = date$("days")
   while  time$("ms") + 3600*24*1000*k  < tt + pp
   k = date$("days") - dd
   wend
End Sub

Function cr$(k)                             ' Gives k carriage returns [chr$(13)]
   for i = 1 to k
   cr$ = cr$; chr$(13)
   next i
End Function

Function ul$(apn, b, nmbr) ' v5.0       ' positions before the dot; behind it; number to display
                                        ' inserts comma's in integer part if apn is Negative
a = abs(apn)                            ' apn: aposneg
ntc$ = chr$(10); "At least One Integer Position Required"; space$(5); _
       chr$(10); chr$(10); "You can print < 0.25 >, not < .25 >"; chr$(10)
if a = 0 then notice ntc$ : exit function
      for n = 1 to a
      a$ = a$; "#"
      next n
   if b<>0 then
      for n = 1 to b
      b$ = b$; "#"
      next n
   dot$ = "."
   end if
ul$ = using(a$; dot$; b$, nmbr)                       ' using() applied to nmbr
if (apn>0) then exit function
if (left$(ul$,1)="%") then perc$ = "%"  :  j = j+1    ' starting COMMA FORMATTING
if (nmbr<0) then sign$ = "-"  :  j = j+1              ' j = number of prefixes
   while (asc(mid$(trim$(ul$),k+j+1,1)) >47) and (asc(mid$(trim$(ul$),k+j+1,1)) <58)
   k = k+1                              ' k = no of numerals in integer part of nmbr
   wend
anmbr$ = mid$(trim$(ul$), j+1, k)       ' the numerals in the integer part of nmbr
bnmbr$ = right$(ul$, b)                               ' decimal part of nmbr
ldspace = a - len(sign$) - len(anmbr$)                ' no leading spaces from using() function
seprtot = int((a-1)/3)                                ' total no separators
seprcma = int((len(anmbr$)-1)/3)                      ' no of separators that is commas
seprldspace = seprtot - seprcma                       ' no of separators that is leading spaces
i = len(anmbr$) mod 3  :  if i = 0 then i = 3         ' i = number of positions left of next comma
   if a > 3 then
   for n = 1 to seprcma
       anmbr$ = left$(anmbr$, i); ","; mid$(anmbr$, i+1)
       i = i+4
   next n
   end if
ul$ = perc$; space$(ldspace+seprldspace); sign$; anmbr$; dot$; bnmbr$
End Function


Dus dat is het : zo'n beetje 4,000 kB voor een bitmap van het hele scherm; wat meer dan dat voor 25x een bmp met dezelfde bmpName; ruim 100,000kB voor 25 bmp's met steeds een andere bmpName.

Vr groet,

George Pape.
glpape
 
Berichten: 83
Geregistreerd: za nov 08, 2008 5:32 pm

Keer terug naar Tips en informatie

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron