|
-
Jan 26th, 2002, 02:05 PM
#1
Thread Starter
Lively Member
A difficult Question
Here is something I've been struggling with for a long time.
Below is the code that generates memory dc's (in type long variables) for a game I'm writting.
For the most part I just hold the same dc's in memory once they are created so everything runs fast. But what I would like to be able to do is delete certain dc's, and then replace them with different pictures so like if you change clothes only one set of clothing dc's will be in memory at a time.
Currently not only does putting a new dc into the long variable NOT save memory but it also compleatly screws up the the sprites ability to display correctly. Any help would be appreciated.
Public Function GenerateDC(Sprite As String)
Dim DC As Long, pictemp As IPictureDisp
DC = CreateCompatibleDC(0)
'If DC < 1 Then
' Exit Function
'End If
Set pictemp = LoadResPicture(Sprite, bitmap)
SelectObject DC, pictemp
DeleteObject pictemp
Set pictemp = Nothing
GenerateDC = DC
End Function
Private Sub createDCs()
Stance1s = GenerateDC("STANCE1S")
Stance2s = GenerateDC("STANCE2S")
Stance3s = GenerateDC("STANCE3S")
Stance1m = GenerateDC("STANCE1M")
'---------many more of these...
end sub
All will fall before the might of the Black Sashi...
-
Jan 29th, 2002, 09:37 AM
#2
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC as Long) as Long
Call this when you want to delete a DC.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 29th, 2002, 10:20 AM
#3
Thread Starter
Lively Member
memory
Well the whole point is to save memory. Simply deleting the old DC then setting a new value to it doesn't save anything it leaks memory somehow. In fact if I just added more dc's I'd be using the exact same amount of memory as deleting and replacing them, only I wouldn't have a leak. I'm starting to think that is the only solution.
All will fall before the might of the Black Sashi...
-
Jan 29th, 2002, 04:10 PM
#4
I don't think DeleteDC leaks anything.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 29th, 2002, 04:33 PM
#5
Thread Starter
Lively Member
why don't you try it then?
try it. If you loop the process around 1000 times or more depending on the size of the bitmap you are using you'll see that replacing dc's leaks memory if all you use is the deleteDC function.
All will fall before the might of the Black Sashi...
-
Jan 29th, 2002, 07:02 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|