Friday, August 05, 2016

Optimizing AS3 Memory Allocation

1. The Problem

The flash client of our game encountered some problem similiar to what’s been described in Memory Fragmentation.
In summary:
  • Our client is multithreaded ( using Workers in actionscript)
  • One of the thread (Logic) depends of several modules written in c/c++ which are compiled by crossbridge.
  • These c/c++ modules need to allocate a lot of memory.
  • The Logic thread needs to be restarted from time to time, so these memory will be freed and allocated from time to time.
The problem is that on a Win 32 platform, at some point, these c/c++ module will fail to allocate memory.
The reason is that, according to the article, c/c++ modules need consecutive memory for all of it’s heap and stack, but due to fragmention and limited virtual memory space on win32, flash failed to allocate them.