Tour de WebAssembly Table des Matières

[Untranslated] Allocators

As we can see to properly communicate objects, we need to have some kind of storage mechanism for objects:

The implementation of something like this is called an allocator. This is beyond the scope of this tutorial. We could imagine a very naive implementation of this which is essentially just an ever growing vector where when an object is stored in the vector and it's index is returned as the handle.

let storage = [];

function storeObject(obj){
  let index = storage.length;
  storage.push(obj);
  return index;
}

function getObject(handle){
  return storage[handle];
}

function releaseObject(handle){
  return storage[handle] = null;
}

There are many issues for you to consider with your implementation.