Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ALLEGRO_VIDEO_BITMAP using more RAM than ALLEGRO_MEMORY_BITMAP

This thread is locked; no one can reply to it. rss feed Print
ALLEGRO_VIDEO_BITMAP using more RAM than ALLEGRO_MEMORY_BITMAP
Turbine
Member #13,178
August 2011

I'm not sure whether this is a bug or a lack of understanding on my part.

I believe setting the flag for newly created bitmaps 'ALLEGRO_MEMORY_BITMAP' should store the bitmap in system memory. 'ALLEGRO_VIDEO_BITMAP' should store the bitmap into video memory, which should use less system memory?

The amount of RAM consumption is:
ALLEGRO_VIDEO_BITMAP: 80,292k
ALLEGRO_MEMORY_BITMAP: 9,420k

Test:

    ALLEGRO_BITMAP* b;
    al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
    for(int i = 0; i < 100; i++)
       b = al_create_bitmap(255, 255);

    ALLEGRO_BITMAP* b;
    al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
    for(int i = 0; i < 100; i++)
       b = al_create_bitmap(255, 255);

Also this causes the program to crash, just 16 with alpha: al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA);

Elias
Member #358
May 2000

It might be that your graphics drivers keep another copy. Can you check how much of the RAM is allocated in your program, in the Allegro DLL, and by the operating system? Also some graphics chips can use shared memory so whatever is allocated in video RAM counts as normal RAM.

If your using the DirectX driver, you could try using the ALLEGRO_NO_PRESERVE_TEXTURE flag and restoring your bitmap whenever you get an ALLEGRO_EVENT_DISPLAY_LOST event. It may cause Allegro to drop one extra copy of the bitmap. Otherwise with DirectX you have three copies: The one Allegro keeps to restore the bitmap whenever the display is lost, the copy your graphics driver keeps, and the copy in (possibly shared) video card memory.

[edit:] In addition to all of that, the operating system will usually not free memory immediately but only at the end of the program. So even if Allegro and graphics drivers only make a temporary copy of the bitmap it can stay allocated until the program ends.

--
"Either help out or stop whining" - Evert

Turbine
Member #13,178
August 2011

Thanks for your reply, It's incredible to think such a massive difference of memory is used despite it possibly using shared memory. Would have thought the 512mb of dedicated video memory would have been used first.

Also is it possible to use the DirectX driver for 2D? Can't find any mention for this, only Direct3D.

Jonatan Hedborg
Member #4,886
July 2004
avatar

What's the bit depth of the bitmaps you are creating? 255*255*100*4 (32 bpp) should be 26MB minimum.

Thomas Fjellstrom
Member #476
June 2000
avatar

Turbine said:

Would have thought the 512mb of dedicated video memory would have been used first.

If its actually dedicated, it will be.

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

Turbine
Member #13,178
August 2011

Yes, it actually is.

510mb dedicated with 730mb shared memory.

@What's the bit depth of the bitmaps you are creating?
I tried 16bit with no alpha and that took up 50mb.

Go to: