Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Memory usage too high? [A5]

This thread is locked; no one can reply to it. rss feed Print
Memory usage too high? [A5]
Hyena_
Member #8,852
July 2007
avatar

I am developing an adventure game. It has much scenery art 800*600 png files and sprite sheets of 1200*1024. Task manager shows memory usage of 208MB currently and it starts to concern me. I guess when all the png images are held in video RAM as bitmaps then it obviously occupies so much memory but what could I do to optimize this and how high should be the maximum memory usage for such an artistic game? I mean most games take much memory nowadays but how much is too much for a 2.5D adventure game? It is a room based game so that when you move to next room it could be possible to quickly load new graphics from disk and destroy old. In that case I hope it won't use too much time to load from later planned zip virtual FS.

Trent Gamblin
Member #261
April 2000
avatar

Only load the pngs that are needed for the current scene.

raynebc
Member #11,908
May 2010

If you're storing the uncompressed bitmaps in memory, it may be a reasonable compromise to store the compressed PNG data in memory instead. They can be decompressed into memory as needed.

Hyena_
Member #8,852
July 2007
avatar

In that case, how to load a png image from memory? How to load a file into memory as it is in the first place and later on how to convert a png in RAM into bitmap in VRAM?

torhu
Member #2,727
September 2002
avatar

This will give you the general idea. Add error checking, and please don't try to compile this code as-is. :)

    /* read image file into memory */
    ALLEGRO_FILE* file = al_fopen("file.png", "r");
    int64_t size = al_fsize(file);
    void* buffer = al_malloc(cast(size_t)size);
    al_fread(file, buffer, size);
    al_fclose(file);

   /* create bitmap from memory */
   ALLEGRO_FILE *memfile = al_open_memfile(buffer, size, "r");
   ALLEGRO_BITMAP *al_load_bitmap_f(memfile, ".png");
   al_fclose(memfile);
   al_free(buffer);

http://alleg.sourceforge.net/a5docs/refman/memfile.html

raynebc
Member #11,908
May 2010

Do seek operations work properly on memory buffered files?

Thomas Fjellstrom
Member #476
June 2000
avatar

raynebc said:

Do seek operations work properly on memory buffered files?

To the degree that you can seek inside the buffer sure. Trying to seek outside, or write/read outside the buffer will cause functions to return errors.

--
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" -- https://twitter.com/neiltyson/status/592870205409353730

raynebc
Member #11,908
May 2010

That's good, I just wanted to make sure it would properly return EOF if the end of the buffered file was reached.

Neil Walker
Member #210
April 2000
avatar

torhu said:

This will give you the general idea.

What's wrong with loading the bitmap as a memory bitmap then transferring to video as required instead of loading into a memory block using the code shown?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

torhu
Member #2,727
September 2002
avatar

He wouldn't save any system RAM that way...

Go to: