export default function() {
let allocations = [null];
let empty = [];
return {
a:function(value){
let i = allocations.length;
if(empty.length > 0) {
i = empty.pop();
}
allocations[i] = value;
return i;
},
r(handle){
allocations[handle] = undefined;
empty.push(handle);
},
g(handle){
if(handle < 0){
return undefined;
}
let ret = allocations[handle];
if(handle !=0 && !ret){
console.error(`Asked for ${handle} after it was released.`)
}
return ret;
}
}
}