Memory Managment

BlitzMax Forums/BlitzMax Programming/Memory Managment

plash(Posted 2007) [#1]
Is this:
Framework BRL.D3D7Max2D
Import BRL.BMPLoader
Import pub.zipengine
'SetGraphicsDriver D3D7Max2DDriver()

Local zrObject:ZipReader = New ZipReader
Local ramstream:TRamStream = Null
Global myram:Byte Ptr
Global myImage:TImage

If ( zrObject.OpenZip("data.pk3") ) Then
	ramstream = zrObject.ExtractFile("gfx/hail.bmp")
	myram = MemAlloc(ramstream._size)
	myImage = LoadImage(ramstream)
	zrObject.CloseZip()
	CloseStream(ramstream)
	ramstream = Null
	MemFree myram
End If

Graphics 800,600,0

While Not KeyDown(KEY_ESCAPE)
	DrawImage myImage, MouseX(), MouseY()
		Flip
	Cls
Wend

End


a correct way to manage memory?

EDIT: A .pk3 file is a renamed zip, just in case anyone was wondering.


Azathoth(Posted 2007) [#2]
You should be checking the return values, and whats with the MemAlloc if you're not using the memory? I mean you're just allocating memory and freeing it.


plash(Posted 2007) [#3]
Yeah, I just realized none of the memory stuff is required, did some tests (which I probably should of done before I made this thread) and found that the memory used by the program is consistently the same throughout the program.