GCMemAlloced() question

BlitzMax Forums/BlitzMax Beginners Area/GCMemAlloced() question

Galdy(Posted 2014) [#1]
I was testing out an image loading function with GCMemAlloced().
Before images are loaded i get 39936 and after i get 141694 bytes. Yet I loaded 52 megs of .png images. So what gives? I want to know what the uncompressed graphics are actually gobbling up. Apparently GCMemAlloced() does not take that into account or do you have to draw the graphics for them to be taken into account? Not understanding.


Gabriel(Posted 2014) [#2]
You probably have to draw them before they get pushed into VRam, which would explain why they didn't count for graphics memory usage, but I would expect GCMemAlloced to report the correct result regardless. If you're not drawing them, and this is only a test app, are you sure they're not being collected again? You're storing them in variables which are in scope?

That said, it's easy enough to calculate memory usage for images without using the GC. Just round up to the nearest power of two, then multiply by the number of bits (or bytes) per pixel.

EG: I have an image which is 57x53 pixels and has an alpha channel.

It'll be rounded up to 64x64 pixels (NPOT) and, with an alpha channel, it'll occupy 4 bytes per pixel. Total memory usage in kilobytes is therefore 64x64x4 / 1024. 16kb.

If you load a full set of mipmaps, multiply that by 1.333.


Galdy(Posted 2014) [#3]
Well when you have over 370 images of varying size, long hand math is not to appealing. lol. I'll create a loop and draw them and see what happens.


Galdy(Posted 2014) [#4]
After drawing them all once, I get 189,440 from GCMemAlloced. That still can't be right. I'm still looking for a batch method of determining my images memory usage. Short of writing a program to do so I guess.


Galdy(Posted 2014) [#5]
Ok. Well I wrote a quick little Vram calculator program. Wasn't to hard.I'm running at about 318 megs. I am assuming the default Graphics depth is 32bit?


xlsior(Posted 2014) [#6]
I am assuming the default Graphics depth is 32bit?


Yes. (Although I seem to remember that even if you force a 16-bit video mode to draw to, the images may still be stored in 32-bit format in memory)


Galdy(Posted 2014) [#7]
Although I seem to remember that even if you force a 16-bit video mode to draw to, the images may still be stored in 32-bit format in memory


Oh? I was just thinking of 16 bit to reduce memory usage of the images, but maybe not uh? Would be nice to confirm that.


Gabriel(Posted 2014) [#8]
It's been a very long time since I used BlitzMax, so definitely don't take my word for it, but it was also my understanding that BlitzMax images are 32 bit internally.