Pergunta de entrevista da empresa Electronic Arts

What is memory fragmentation? Why is it relevant to a game program? What can be done to avoid it?

Resposta da entrevista

Sigiloso

25 de out. de 2024

This is a huge question, and I think I nailed it. Memory fragmentation effectively causes "holes" in a computer's RAM that stop being useful for the remainder of the game's runtime. This happens because "list"-type objects are common in the development of a game, and the only limits on lists' sizes are practical ones. A list can easily contain hundreds of thousands of objects. Some of these lists require "contiguous" memory space; i.e., those hundreds-of-thousands of objects, all have to be beside each other in one unbroken span. Asking for several of these spans eventually overcomes the CPU's ability to locate available memory of the requested size. In brief, some solutions include: non-contiguous list types, such as linked lists object pools, which are reserved at program initialization, and distributed according to a model that the team makes in-place filtering and sorting techniques that do not require new lists to be requested management of list CAPACITY versus COUNT; storage for far more list elements than you need immediately ensures the space is there when you do need it aggressive "garbage collection" of dead objects, paired with frequent "defragmentation" of RAM (similar to Disk Defragmentation in all the ways that matter)