jirihybek / unity-websocket-webgl

Hybrid WebSocket implementation for Unity 3D with support of native and browser client.
Other
248 stars 61 forks source link

Support for length param when sending to avoid allocating byte array. #9

Open johnou opened 5 years ago

johnou commented 5 years ago

We can exploit the fact the WebGL implementation takes a byte array and length ( instance.ws.send(HEAPU8.buffer.slice(bufferPtr, bufferPtr + length)); ) and allow the application to write to a buffer then pass that into the websocket send function instead of always allocating a new byte array eg.

int outputBytes;
while ((outputBytes = _tls.ReadOutput(_outgoingBuffer, 0, _outgoingBuffer.Length)) > 0)
{
  _socket.Send(_outgoingBuffer, outputBytes);
}
johnou commented 5 years ago

ptal @jirihybek cc @endel

johnou commented 4 years ago

@jirihybek poke, wdyt?