FlushMem. What's official word?

BlitzMax Forums/BlitzMax Programming/FlushMem. What's official word?

GW(Posted 2005) [#1]
I can't find anything definitive on the boards about the best way to use flushmem and the docs are next to useless.

Are we only supposed to call flushmem in one place in the main loop or are we supposed to sprinkle it around our sub-modules to prevent it missing things?

No speculations please!
Can I get someone from BRL to give an official response??


skidracer(Posted 2005) [#2]
From Help->Tutorials->BlitzMaxMemoryManagement

FlushMem should be placed in your program's 'main loop', and perhaps at other 'hotspots' in your program where you have created a lot of objects - for example, after loading a game level.




GW(Posted 2005) [#3]
Well, I've gone back over my project and removed all calls to flushmem except for my main gui loop (options screen before the game starts) and the main game loop and now I have memory leaks. There *is* something wrong with flushmem, or the documentation is missing some critical piece of info that we should know.
Not to mention the fact that memalloced() is grossly inacurate compared to what windows is telling me. 30meg for memalloced() vs. 106meg for windows.


skidracer(Posted 2005) [#4]
OK I agree the docs suck.


Mark will correct me if I'm wrong but here goes -

MemUsage should agree with the system not MemAlloced

BlitzMax never frees any memory, whenever an object is freed the memory goes to an internal recycling mechanism which is a lot faster than going to system when a similarly sized object has to be allocated in future.

This means that at some point your program was using 106 meg.

From experiencve file parsing can be an expensive thing, if you are constructing Strings in a loop and that loop clocks more than a few 1000 iterations it is well advised to add a flushmem.

Currently BlitzMax grows it's internal heap in a really really slow way so if you are abusing the heap a flushmem will actually improve performance as recycling memory is currently far faster than allocating system memory.


I'm of course not ruling out problems in the flushmem code, see here for example.


GW(Posted 2005) [#5]
Ah.. I see!
That makes a lot more sense.
Thanks for clearing that up!
[you should formalize that and make it sticky thread] :)


Perturbatio(Posted 2005) [#6]
mind if I add it to the wiki?


skidracer(Posted 2005) [#7]
np