Available memory?

BlitzMax Forums/BlitzMax Beginners Area/Available memory?

ima747(Posted 2010) [#1]
is there a way to figure out how much ram is available without allocing blocks until it fails? additionally is there a limit to the managed memory (as reported by GCMemAlloced()) can be used?


Brucey(Posted 2010) [#2]
I think max application memory for a 32-bit app is 2GB.


ima747(Posted 2010) [#3]
that's what I thought but freeimage seems to start giving me unable to allocate errors when it gets a little over 1gb as reported in task manager (vista x64 with 4gb real ram).

Is there any way to get the allocated ram in bmax (since GCMemAlloced() just gives managed memory)?


Brucey(Posted 2010) [#4]
1 GB?

Those are either, very, very big images, or you are hanging onto far too many objects?


ima747(Posted 2010) [#5]
both, but sadly that's kinda the point of the program, to display a lot of big images at the same time, which is why I need to manage them pretty closely to eek out as much as possible at once.

Althought I did just find a retain I didn't need so that frees up a huge chunk of ram, but I still need to keep an eye on how much ram is loaded/free so I know when I'm getting close to overload and can unload some things (I need to retain them until I have no choice but to get rid of them)


Brucey(Posted 2010) [#6]
You have have a huge screen then!

Can't you load and thumbnail them into pixmaps, tossing away the original big versions?
Then if you really need to show a big one, just reload it?

I suppose it depends what you need to do with them, of course.


ima747(Posted 2010) [#7]
hehe sadly those are the thumbnails... wish I could send you a demo so you'd see the method to my madness, but NDA forbids it at the moment.

Basically I just need a way to keep a close eye on the ram usage rather than guessing based on a rough calculation of how much space each pixmap should take up... as that doesn't factor in things I'm un-aware of, like objects being used by modules and such. Once I know how much is being used I can figure out a safe ceiling and just keep underneath it with some buffer space for loading and various other here and there jobs.


ImaginaryHuman(Posted 2010) [#8]
That would have to be a 1gb *contiguous* block of memory which may not be availble after memory fragmentation, even if the total available is more than that.


Zeke(Posted 2010) [#9]
windows only:
Extern "win32"
	Function GlobalMemoryStatusEx(buffer:Byte ptr)
End Extern

Type _MEMORYSTATUSEX
	Field Length:Int
	Field MemoryLoad:Int
	Field TotalPhys:Long
	Field AvailPhys:Long
	Field TotalPageFile:Long
	Field AvailPageFile:Long
	Field TotalVirtual:Long
	Field AvailVirtual:Long
	Field AvailExtendedVirtual:Long
End Type

Local info:_MEMORYSTATUSEX = New _MEMORYSTATUSEX
info.Length = SizeOf(info)

GlobalMemoryStatusEx(info)

Print "Memory Load= " + info.MemoryLoad + "%"
Print "Total Physical Memory= " + info.TotalPhys Shr 20 + "Mb"
Print "Avail Physical Memory= " + info.AvailPhys Shr 20 + "Mb"
Print "Total Page File= " + info.TotalPageFile Shr 20 + "Mb"
Print "Avail Page File= " + info.AvailPageFile Shr 20 + "Mb"
Print "Total Virtual Memory= " + info.TotalVirtual Shr 20 + "Mb"
Print "Avail Virtual Memory= " + info.AvailVirtual Shr 20 + "Mb"



ima747(Posted 2010) [#10]
Awsome Zeke, I'll give that a shot ASAP. anyone have anything similar for mac as well?