As an optimization, I decided to put an object I frequently need - an SDL surface with a prerendered image of the entire level (called S_AreaBMP) - at global scope.
Now it doesn't have to be created and destroyed in the DrawScreen function every frame. I only need to dispose and change it when a new level or GFX sheet is loaded, which I do via this function:
Public Sub PrepareAreaImage()
''#dispose old image before it becomes unreferenced
If AreaBMPExists
S_AreaBMP.Dispose()
End If
AreaBMPExists = True
''#declare an appropriately sized bitmap w/ a GDI Graphics object
Dim AreaBMP As Bitmap = New Bitmap(Area.W * TLDIM, Area.H * TLDIM)
Dim AreaGrph As Graphics = Graphics.FromImage(AreaBMP)
''#...(omitted: iterate through Area and draw each tile to AreaBMP)
''#Store to the SDL surface
S_AreaBMP = New SdlDotNet.Graphics.Surface(AreaBMP)
''#Dispose
AreaBMP.Dispose()
AreaGrph.Dispose()
End Sub
(AreaBMPExists and S_AreaBMP are global scope)
Question: Is this fundamentally sound?
It works fine, but I can't help but feel that this sort of thing is discouraged...