Do you use D's GC?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 2 21:51:21 UTC 2021


On Mon, Aug 02, 2021 at 03:43:24PM +0000, IGotD- via Digitalmars-d wrote:
[...]
> I'm kind of skeptical towards tracing GC for games. Think of thousands
> of objects, usually of the same type. These objects are often full of
> references to other objects and they often points to each other as
> there might be some relation.
[...]

I don't have that much experience with game programming, but have
experimented with things like ECS, which kinda solves this problem at
least partially, by keeping everything in arrays.  References between
objects are represented by entity IDs rather than straight pointers, and
arrays can be allocated in large blocks at a time instead of one
allocation per object, so there's much less GC pressure.  ECS is also
more conducive to representing in-game objects than OO-style objects
IMO, especially in games where objects can undergo extensive changes
that aren't easily mapped to the OO paradigm.

Of course, an ECS implementation could also just manage its own memory
instead of relying on GC.  In any case, high performance + frequent
allocation of small objects == trouble (even if you manually manage
memory with malloc/free).  If you find yourself in that situation, you
inevitably have to address a lot of the same kind of issues that ECS
addresses anyway.  So this problem isn't necessarily GC-specific (though
it tends to become more evident in GC environments), but a more general
problem of memory management and object representation in games.


T

-- 
MASM = Mana Ada Sistem, Man!


More information about the Digitalmars-d mailing list