In C++ we can allocate a local object to the stack or the heap. Stack allocation is very fast as the only overhead is decreasing the stack pointer by the size of the object. Stack memory is fast as it is likely to be in the cache. If an object is allocated to the heap, the memory manager will have to find a free chunk of memory and mark it as in use. Heap allocation is therefore slower than stack allocation. For temporary objects whose lifetime is the length of the function the stack is a more efficient method for allocating memory.
On each occasion where we use a temporary object, instead of creating a new local object on the heap we could reuse an existing ‘temporary’ object. This strategy is known as ‘Object Pooling’ where temporary objects are fetched from an existing pool rather than created, and returned to this pool rather than being destroyed.
Thus we implement functions with a strict rule of whenever possible not allocating new local objects in the methods, ‘whenever possible’ is included in this rule because sometimes we might not have enough objects in our object pool, in this case a method of creating a new object in the pool is provided.
Today I am currently looking at how their implementation will fit with my existing code. gamecore.js uses class.js – a script that builds class like behaviour using JavaScirpt prototype object model. Although I have been using the prototype chain as an equivelent of a class-definition, especially for sub-classing in the cases where it is (rarely thankfully!) needed, I am trying to stay away from just ‘fixing’ the prototype system by creating a layer code just to implement classes – this is purely an experiment to challenge my own thinking and to prove or disprove that C++/Java style OOP is the be-all and end all. The downside is that (I think, not read the whole thing yet!) the gamecore.js object pooling code is written for a ‘class’ based object system, I appreciate that it basically works like Singleton pattern, in that it uses a static ‘factory’ method on the class, but I don’t know what or where my static methods would live, in the constructor? in the prototype? I’m guessing the prototype would be faster as _proto_ links are optimised (they’re invariants) and .constructor links are not (although with inline cache I think .constructor property would get optimised if you hit it a lot) .
This isssue will be solved by Saturday night, or I will, um, be sorry.
The title of my project is: ‘The Development of a tool to facilitate the production of animated interactive learning materials, games and simulations’
The aim of my project is: To develop software to facilitate teachers, developers, educators and learning technologists in the production of animations, simulations and games as learning material.
The Objective of my project is: To develop a game engine for use in an educational context.
My intention is to ultimately situate a game engine and authoring tools within a online virtual learning environment (VLE) providing not just tools for creating and displaying this content but also assisting with feedback to the VLE to monitor students progress using the material, even potentially setting learners the task of authoring their own content – and getting feedback from this.