09 April 2022, 12:05 | #1 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,894
|
Memory Management
Prompted by my Flappy Bird game not running on an unexpanded A500, I thought a discussion on saving memory (especially with graphics) might be useful. So please discuss/post tips etc.
|
09 April 2022, 12:11 | #2 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,894
|
I'll start by bringing up Daedulus' comment in another thread. He suggested that by loading lots of graphic files individually that this can lead to memory fragmentation. Therefore would it be better to load in one file and grab images from this? Do others do this or have other ways of getting graphics into games?
|
09 April 2022, 18:34 | #3 |
Rumpig
Join Date: Aug 2006
Location: The bottom of the bottle
Age: 92
Posts: 243
|
Does not fragmenting threads prove a point?
|
09 April 2022, 21:59 | #4 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
|
To be fair, the discussion wasn't really on topic in the other thread, which was about Amiga Addict magazine so it makes sense to create one here.
But anyway, loading or creating a graphical object will allocate an area of chip RAM to store the graphical data. That area will be located at the first free area that's large enough. The next object loaded or created will do the same, which means it will often appear next to the previous object in memory. Now, this is fine until you don't need some of them any more. You can free the objects you don't need and that will free up their RAM, but it doesn't move the location of any later objects which weren't freed, so what happens is that you have a small bubble of free RAM surrounded by used RAM. When you then need to create a larger object, it won't fit into any of those small empty bubbles, even if it's smaller than the amount of RAM they collectively take up. In this respect, whether you grab the shapes from a single file or load them individually doesn't make much difference - the problem is that if you free some of them up later it's difficult to reuse the RAM they took up. One possible approach is to make sure the objects that will be freed up are all the last objects to be created. That way, when you free them up, their space is all side-by-side and therefore is a single, large block when it's freed. And if nothing else is allocated in the meantime, that large block will be next to the rest of the free chip RAM, meaning it can be used for much larger objects. In your particular example, this is complicated by creating sprite objects from the shapes. The first thing to do though is to load all the shapes first, then create your sprites. This way, at least the shape objects will be side-by-side in RAM, instead of being Shape-Sprite-Shape-Sprite... So when you free the shapes, at least you'll have a single free block the size of all the shapes, instead of a single shape-sized block in between each sprite and the next. |
10 April 2022, 19:22 | #5 | |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,894
|
Quote:
|
|
10 April 2022, 19:24 | #6 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,894
|
Is there any way of getting screen chip ram back? If so, as I open a dual playfield screen and third/fourth screens (for the start/game over) at the end - I could close the dual playfield screen before opening the game over? Is this sort of thing possible?
Also, I load some quite large files into shapes at the beginning of the game so there is no loading once the game is running but I could load some of these files when needed and then free up afterwards. Will have a little play with this as could be quite useful to get my head round it and might help others with their memory management. I think part of the problem is that I am still thinking like a pc programmer with basically 'unlimited' ram! Last edited by Havie; 10 April 2022 at 19:32. |
10 April 2022, 21:38 | #7 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
|
The screens themselves in this context don't take up much RAM. They just point to a bitmap in memory and display that as required, and it's the bitmap that takes up all the RAM. You can free bitmaps, but be careful of doing so if they're in use or going to be in use again - blitting to a non-existent bitmap is bad news.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Personal Paint 7.1 memory management | Dradd | support.Apps | 2 | 13 February 2022 11:38 |
File management | marm | New to Emulation or Amiga scene | 21 | 04 November 2018 13:41 |
Question about Amiga memory management | Kenan | support.Hardware | 1 | 18 June 2013 07:20 |
Better (perhaps) config files management | NewDeli | request.UAE Wishlist | 7 | 24 June 2008 15:43 |
Icon Management | Makkinen | support.WinUAE | 3 | 16 October 2004 00:30 |
|
|