comp.lang.ada
 help / color / mirror / Atom feed
* Memory management in games
@ 2004-11-27 19:48 Luke A. Guest
  2004-11-28  0:53 ` David Botton
  2004-11-28 10:41 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 4+ messages in thread
From: Luke A. Guest @ 2004-11-27 19:48 UTC (permalink / raw)


Hi,

Further to my posts in the game dev thread, I've decided to go back on my
original thoughts and do the game engine in Ada (I can always *cough* port
*cough* gnat *cough* ;-D).

Now, one of my design requirements is that I *must* be able to see *all*
memory allocations and track them, this is so I can build in debugging
tools into my engine. I have just done this in C++ by overriding the
global new/delete operators and using macros to redefine
new/delete/mallo/free/calloc/etc. to point to my new memory management
class. These macros also pass the filename and line number from where the
memory was allocated. Also, this class keeps track of all allocations in a
list template. I currently just dump out the contents of the list on exit.

So, I need to be able to do the same in Ada. Enter Storage Pools, ok, it's
not difficult to write a pool class, I've just written a simple one. But,
what a game engine requires is the ability to allocate a big block of
memory and then allocate other blocks from this, so it's like a
hierarchical pool system.

e.g. Under Linux, I might allocated a block of memory to use for the
entire game (from a start up script), say 50Mb and this will be used for
this session

e.g On a PS2 we have something more challenging, the underlying OS needs
some memory to load the game ELF and have some memory to use for it's own
data structures, so in the game I say, give me 25Mb for this session.

Then from this pool, other pools/objects are allocated. So, I need a way
to override the default memory allocation method for everything, including
library routines. Can this be done portably? I know I can specify the
T'Storage_Pool for a type, will this work for libgnat.a types as well?

I've seen that GNAT provides the System.Memory package, this isn't
standard, so should I just go out of my way and import the memory
allocation functions I require (malloc on Linux, memalign on PS2, etc.)?

Also, what would be the best method of passing the function name where the
allocation call is, through to the allocator, so that I can show where an
allocation was made? I could use gnatprep I suppose, but obviously would
prefer to be portable. FYI, there will be two builds as memory allocation
tracking would not be in the final release mode build as it's extra
overhead.

Thanks,
Luke.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-28 10:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-27 19:48 Memory management in games Luke A. Guest
2004-11-28  0:53 ` David Botton
2004-11-28  1:43   ` Luke A. Guest
2004-11-28 10:41 ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox