- Online Community Forums » Programming Questions » Getting size of ALLEGRO_BITMAP

This thread is locked; no one can reply to it. rss feed Print
Getting size of ALLEGRO_BITMAP
Member #14,871
January 2013

I am writing a resource manager for my game which should tell if some limit of allocated resources has been breached and delete some least used resources in this case (as well as allocate resources, count how much memory is in use for these resources etc.).
However, I found that images take up much more space in memory than on disk, and I have no idea how to get the size of an uncompressed ALLEGRO_BITMAP. Is there a way to do this?

Thomas Fjellstrom
Member #476
June 2000

ALLEGRO_BTIMAP *bmp = al_load_bitmap("foo.png");
int size = al_get_bitmap_width(bmp) * al_get_bitmap_height(bmp) * al_get_pixel_size(al_get_bitmap_format(bmp));

That should do it.

Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" --

Member #14,871
January 2013

That's a good idea, thank you, Thomas.

Member #11,410
October 2009

Note that if you use mipmapping, these numbers won't be totally accurate for vram usage.

Also note that, in some cases, such as using texture preservation in D3D, Allegro keeps a backup of the texture in system memory.

Also, in cases where non-power-of-2 textures are not supported, Allegro might pad your bitmap to PO2, so that might take up more memory. Sometimes too, the graphics driver will do this too.

Also, if you use Windows, you may want to try MSI Afterburner.

This neat tool can tell you how much vram is in use. So before you start your app, just note how much vram is used, and the difference between the value when your app is running and this start value is how much vram your app is consuming.

Go to: