Unloading Objects

Blitz3D Forums/Blitz3D Programming/Unloading Objects

pc_tek(Posted 2010) [#1]
Hi all!

My program runs ok, but it is rather annoyingly slow to 'unload' itself from memory after it terminates. There are 840 32x32 tiles.

Is there a way to speed this up? Or should I just upgrade my PC?


Axel Wheeler(Posted 2010) [#2]
Are you sure it's your program? Do other Blitz programs (like the samples) exit more quickly?

You might want to watch Task Manager before, during and after the run. Watch the cpu usage and page file usage. Does memory continue to get gobbled up even after all the tiles are created? If so, you may have a memory leak in the program (allocating memory over and over again).

Here's one idea: If the tiles are quads or meshes that are similar to each other, consider using CopyEntity() rather than separate meshes. I don't know if you can texture them differently, but you can color them differently and scale them differently, if that helps.

Good luck!


pc_tek(Posted 2010) [#3]
It is just the amount of tiles I have loading up that is taking so long to release once the program has ended.

Thank for the response, I need a better PC for this LOL.


BLaBZ(Posted 2010) [#4]
By tiles I assume you mean quads?

It may be faster if you "AddMesh" each tile with the same texture


Axel Wheeler(Posted 2010) [#5]
Good point. A mesh doesn't have to be a single contibuous shape; you can for example add 100 unique tree meshes to one mesh (being sure to FreeEntity the original meshes, otherwise it's no help!).

There are issues and caveats with this approach though, vertex limits of meshes, multiple surfaces (addmesh tends to create a new surface each time. Consider sswift's excellent AddMeshToSurface function to avoid this)

http://www.blitzbasic.com/codearcs/codearcs.php?code=575

Anyway, if you post the executable or code we can run it on our machines and see if we have the same experience. If it's slow even on a fast machine then upgrading won't help. (not that I have a fast machine, but someone here must!)


_PJ_(Posted 2010) [#6]
Is this your computer's memory management, or the program Free'ing Entities /Textures etc.?

Also, remember that Windows wroites various log files on program termination etc. and HD Disk-Writing is often comparitively slow.


jfk EO-11110(Posted 2010) [#7]
If your Machine is running out of RAM, it will save parts of the System to the harddrive to allow your app to use more RAM. After termination it will reload the System parts, this sometimes takes a lot of time.


_PJ_(Posted 2010) [#8]
Isn't that only if paging/swap file is set? Otherwise the computer just gives a memory low message.


pc_tek(Posted 2010) [#9]
I found out through comprehensive testing that B3d takes almost 4 times as long to 'end graphics' than to load them - on my machine.

My program loads over a 1000 sprites...840 of them from a single image file. It takes the program about a second to compile...and a second to run. But takes 3.96 seconds to unload. So I guess it would all depend on your processor/graphics/ram and HD speed.

I ran the same program on a high-speed machine (dual core) with lots of ram and SATA2 HD's...and it unloaded in under a second.

I don't use the 3d part of B3d at all


Warner(Posted 2010) [#10]
Then couldn't you load the image once, and use it more often instead of loading it 840 times?


pc_tek(Posted 2010) [#11]
@Warner: No...there are 840 32x32 images...which are loaded using the LoadAnimImage command. That plus 200 or so other sprites from other sources....

gfx_tileset=LoadAnimImage("Tiles.png",32,32,0,840)