开发者

Memory usage during drawing procedure

I wrote a small procedure in assembly to draw some text to the screen (fir开发者_如何学Cst it writes to a buffer, then copy the buffer to the screen with BitBlt) The function works well, and it draws every 25ms, but i noticed that the memory usage increases over time, and increases a lot. First, i tried releasing the buffer DC and then delete the bitmap, creating a new one to see if the memory got released but it didnt work, is there any way i can reduce this memory usage?

here is my code

backh dd 0
bmph dd 0
isless db 1
zerod dd 0

initmenu:
          invoke GetDC,0
          invoke CreateCompatibleDC,eax
          mov [backh],eax
          invoke GetDC,0
          invoke CreateCompatibleBitmap,eax,140,250
          mov [bmph],eax
          invoke SelectObject,[backh],[bmph]
          invoke SetBkMode,[backh],TRANSPARENT
          invoke SetTextColor,[backh],33CC00h
          retn

updatescreen:
      invoke GetDC,0
      mov [zerod],eax
      mov cl,[isless]
      test cl,cl
      jnz @f
      invoke BitBlt,[zerod],0,0,140,250,[backh],0,0,SRCCOPY
      jmp _updatescreenend
      @@:
      invoke BitBlt,[zerod],0,0,140,25,[backh],0,0,SRCCOPY
      _updatescreenend:
      invoke ReleaseDC,[zerod]
      retn
menuproc:
          invoke Sleep,25
          call updatemenu
          jmp menuproc 


You have to release the DC. It's possible that you didn't do it right (in the code you presented, the value of DC is lost by the time BitBlt returns).

Can you estimate how much memory you leak per iteration?


Solved the problem, instead of ReleaseDC i should use DeleteDC, the information on MSDN is wrong...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜