Memory management dilemma

mclysenk at mtu.edu mclysenk at mtu.edu
Sun May 28 07:45:24 PDT 2006


In article <e5c89d$6ki$2 at digitaldaemon.com>, Jeff Parsons says...
>
>Hi
>
>Straight to the point: I'm having trouble finding a clean way to make 
>sure memory that's no longer required by my game is freed.
>
>I need to manage memory explicitly since it seems to be impossible to 
>guarantee long-term smooth operation when using only garbage collection. 
>I don't see introducing artificial pauses into gameplay during which 
>garbage is collected, or allowing the game to bloat horribly over time 
>as solutions.
>

I thought about this for a lot as well and here's what I came up with:

Use structs.

In D structs are copy on write, and therefore don't need memory management.
This makes them ideal for simple mathematical primitives, but a terrible idea
for larger objects. Classes on the other hand are pass by reference, and are
allocated only in heap space.

If you would like to see an example, I have a vector/matrix library for
Derelict/OpenGL that I've written.  I can post the source if anyone is
interested.

-Mik





More information about the Digitalmars-d mailing list