[gameprogrammer] Re: memory management in a game with LOTS of art

  • From: "Kevin Jenkins" <gameprogrammer@xxxxxxxxxx>
  • To: <gameprogrammer@xxxxxxxxxxxxx>
  • Date: Sun, 4 Jul 2004 10:31:17 -0700

You can use a LRU algorithm.  For each memory object, keep the time it was
last accessed.  When a page fault occurs, which means that the object you
want is not in memory, overwrite the object that was least recently used.

One optimization for this is to use a queue instead of writing the time.
When an object is accessed, remove it from the queue and push it back.
When a page fault occurs, pop the queue - that is your memory chunk.
Overwrite it, then push it back.  Problem is you have to take an item out of
the middle of a queue, which is slow if you use an array based queue.  You
can fix this by using a linked list queue.

Which is better depends on the number of page faults you expect to have.  If
you have a lot of memory you will want to use the array because a linear
array traversal will be optimized by the compiler.  If you have a little
memory the linked list is better because you don't have to shift an array
every time.

The first method (timestamp) is probably the best for a computer because
linear array accesses are pretty fast.  Some other optimizations I didn't
mention here are mainly for hardware.

----- Original Message -----
From: "Alan Wolfe" <atrix2@xxxxxxx>
To: <gameprogrammer@xxxxxxxxxxxxx>
Sent: Saturday, July 03, 2004 11:40 PM
Subject: [gameprogrammer] memory management in a game with LOTS of art


> Hello all,
> A friend of mine is working on making a 2d tiled online RPG using SDL and
OpenGL.
>
> He has increasingly more art/mem usage as he adds stuff in (obviously) and
was working on a solution to somehow prioritize the art of what stays in RAM
and maybe storing the low priority stuff in files or something?
>
> I dont think he really has a clue and myself, I've never dealt with this
issue before.
>
> Anyone out there know how to deal with this issue, of what to do when you
start to aproach too much art to load all into RAM at one time?
>
> Thanks a bunch!
>
> Alan
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
>



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: