I'm using transferable objects between my main thread and physics worker. The Float32Array is being passed back and forth and it works quite nice. How do I check if Float32Array is neutered?
For example this is an array:
this.transferableArray = new Float32Array();
Send as transferable object
worker.postMessage(this.transferableArray, [this.transferableArray.buffer]);
Currently in my code I check if it's neutered like that:
if (!transferableArray.length) {
return false;
}
Is this the right way of doing it or is there some method which specifically tells if the array is neutered? This is a game so every millisecond gain matters.
Checking for
0
.byteLength
should be enough in 99% of the cases.If you really need to handle the remaining 1%, you can try to call its
slice()
method, which would throw if the ArrayBuffer is detached.