Just have a beginners question (again) as the documentation is a little vague about this.
If I choose to create a sprite with handle 1 and then create a sprite with handle 100. Do I somehow hold up any memory for those handles I left in between or is it just like variables?
Why Im asking is because I want a sprite bank at 1-10 and then a bank spanning over 100-120. I hope I dont hold up/reserve any spritememory in between then.
Spritehandles, good or bad ways?
@AJirenius
make the test, try both #Sprite1 = 1 and #Sprite1 = 999999 and have a look in the task manager, compare for yourself the difference in memory use.
c ya,
nco2k
yes you do... which means, if you use the highest sprite id, the lower ones, will be kind of reserved, doesnt matter if they are actually used or not:Do I somehow hold up any memory for those handles I left in between or is it just like variables?
Code: Select all
Enumeration
#Sprite0 = 0
#Sprite1 = 999999 ;#Sprite1 = 1 try both!
EndEnumeration
hwnd.l = OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "")
If InitSprite() And OpenWindowedScreen(hwnd, 0, 0, WindowWidth(), WindowHeight(), 0, 0, 0)
If CreateSprite(#Sprite1, WindowWidth(), WindowHeight())
If StartDrawing(SpriteOutput(#Sprite1))
For i = 0 To 1000
Box(Random(WindowWidth() / 2), Random(WindowHeight() / 2), Random(WindowWidth()), Random(WindowHeight()), RGB(Random(255), Random(255), Random(255)))
Next
StopDrawing()
Repeat
WinEvent.l = WindowEvent()
DisplaySprite(#Sprite1, 0, 0)
FlipBuffers()
If WinEvent = 0
Delay(1)
EndIf
Until WinEvent = #PB_Event_CloseWindow
EndIf
EndIf
EndIf
End

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
You're absolutely correct nco2k. I'm a little surprised at this.
999,999 sprite handles : 25,892 kb
100 sprite handles : 2, 396 kb
2 sprite (0 and 1) handles : 2,392 kb
However, using #pb_any is a different story. I tried the same code above but used #pb_any for sprite1 (and changed it from a constant). #pb_any assigned sprite1 the handle '8396440' which is nearly 10 times higher than the 999,999 used above. The memory consumed was : 2,396 kb
999,999 sprite handles : 25,892 kb
100 sprite handles : 2, 396 kb
2 sprite (0 and 1) handles : 2,392 kb
My mistake, I'm sorry. AJirenius, looks like a few kb gets wasted for unused handles in your application. It's probably nothing to worry about though.Don't worry about sprites #11-99 as they won't take up memory unless you actually use them.
However, using #pb_any is a different story. I tried the same code above but used #pb_any for sprite1 (and changed it from a constant). #pb_any assigned sprite1 the handle '8396440' which is nearly 10 times higher than the 999,999 used above. The memory consumed was : 2,396 kb
Code: Select all
hwnd.l = OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "")
If InitSprite() And OpenWindowedScreen(hwnd, 0, 0, WindowWidth(), WindowHeight(), 0, 0, 0)
sprite1 = CreateSprite(#PB_Any, WindowWidth(), WindowHeight())
Debug sprite1
If StartDrawing(SpriteOutput(Sprite1))
For i = 0 To 1000
Box(Random(WindowWidth() / 2), Random(WindowHeight() / 2), Random(WindowWidth()), Random(WindowHeight()), RGB(Random(255), Random(255), Random(255)))
Next
StopDrawing()
Repeat
WinEvent.l = WindowEvent()
DisplaySprite(Sprite1, 0, 0)
FlipBuffers()
If WinEvent = 0
Delay(1)
EndIf
Until WinEvent = #PB_Event_CloseWindow
EndIf
EndIf
End