Idea about memory management. Game related.

Walter Bright newshound at digitalmars.com
Fri Jun 2 13:57:58 PDT 2006


The gc will pause all threads when it does a collection, even if those 
threads are in another language.

Some thoughts:

1) The gc will only pause threads it knows about. So you can create a 
thread that is unknown to the gc by calling the operating system thread 
creation APIs directly. However, if you do this, then those threads must 
not manipulate or reference any gc allocated data.

2) Using C++ new or malloc is no guarantee of latency. Neither of them 
have any constraints on how long they take to call, and (due to 
fragmentation) can cause a significant pause.

3) To deal with (2), professional game programmers I've talked to will 
"preallocate" all the data they'll need before running the task that 
cannot be paused.

4) It is very important to realize that the gc will not collect at some 
random time. It will ONLY collect during calls to new. No calls to new, 
no collections.

5) Therefore, to avoid pausing during critical times in the game, avoid 
calling new during those times. You can call malloc() instead if 
necessary. Calling malloc() won't cause the gc to run.

6) Collection pauses can be minimized by running the gc collector during 
  idle loops, such as waiting for user input.



More information about the Digitalmars-d mailing list