Skip to content

The memory usage of threads

Cheng Liao edited this page Jun 23, 2013 · 3 revisions

In common C/C++ programming principle, creating threads is a cheap thing. And threads do not only leverage multiple CPU cores, but also share the memory in the same process. For a large game engine, it usually creates several threads to process different computing tasks, which makes the performance much better. But in FlasCC, the situation is very different. If you create too many threads in a large FlasCC project, you will encounter serious memory issues.

Now let’s explain how the threading is implemented. A thread in FlasCC is not a real thread supported by OS like the native application. Remember that FlasCC can’t do anything AS3 can’t do. In other words, FlasCC can only access the public AS3 APIs provided by Flash Runtime. As you may know, Flash Runtime doesn’t provide any native threading API, so it’s not possible to create real threads in FlasCC. Fortunately, Flash 11.4 introduces Worker feature and Flash 11.5 introduces Shareable ByteArray feature. Thread in FlasCC is based on these two features actually. See this diagram: