Memory usage too high? [A5]

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

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


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.


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?


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);

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


Do seek operations work properly on memory buffered files?

Thomas Fjellstrom
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.


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
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?


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

Thread #608651. Printed from