Game and GC

Dukc ajieskola at gmail.com
Fri Feb 23 10:10:13 UTC 2018


On Friday, 23 February 2018 at 01:54:07 UTC, Leonardo wrote:
> What can happen if I create a game using D without worrying 
> with memory management?
> (using full GC)

If you do not worry about memory management at all, it will 
probably lead to a need to redesign your game. And that's 
regardless whether you allocate manually, via GC or using 
reference counting.

You should laways make sure you do not have to continuously 
allocate in a tight loop. By tight I mean somthing thats executed 
hundreds or thousands of times per second. I do not mean that you 
should not allocate there, but make sure you can easily move the 
allocation out such a loop if necessary.

GC is most likely a good option, as others have said. It does use 
more memory than RC or manual management, and leads to short 
pauses, but is almost as fast as manual management on average. 
You can:

1: Time the garbage collecions manually so that they happen when 
responsiveness isn't important.  It's likely something like 100ms 
so even a short such moment will do. For example, when a racing 
car comes to stop or gets airborne, so that input wouldn't matter 
anyway.

2: If you have long intervals without such pauses, you can 
recycle the all the memory you have freed to make sure the 
program does not accumulate so much that it needs to collect. 
This is hard, so I recommend it only if 1. isn't feasible or you 
want to challege yourself.

If neither of these are possible, or you think your game will be 
at limits of the RAM capacity no matter the optimizations 
(shouldn't happen for an indie game), then you should consider 
avoiding garbage collection from get-go.


More information about the Digitalmars-d-learn mailing list